AWK

↓ Contents ↓
Introduction
AWK: Вывести только определённые столбцы

Introduction

В этой статье Вы можете узнать в основном о работе с AWK.

Про SED вы можете прочитать в статье «Основы SED» про GREP - в статье GREP

По умолчанию я предполагаю, что Вы работаете в Bash под Windows 10

Как установить Bash в Windows 10 подробно описано здесь

Основные команды AWK

Вывести только определённые столбцы

Предположим, что у нас есть файл input.txt следующего содержания

Here is a String it has a Name Here is an Integer it has a Name Here is a Float it has a Name

Мы хотим отбросить всё, что находится левее слова it, включая слово it, и записать в файл.

Аналогичную операцию мы проделывали с помощью sed в этом примере.

awk '{print $6,$7,$8}' > awk_result.txt

$6 означает, что мы выводим элемент из шестого столбца. Результат:

 has a Name  has a Name  has a Name

С помощью awk мы можем вывести произвольные столбцы:

awk '{print $1,$3,$7,$8}' > awk_result.txt

Результат:

Here a a Name Here an a Name Here a a Name

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: