Понимание
С этими блоками автор определяет диапазон, переключая флаг e
, когда входит / выходит из указанного диапазона:
# end of range
/\]\]/ {
e = 0
}
# start of range
/description = \[\[/ {
gsub("^.*description ", "", $0)
e = 1
}
Функция строки gsub
заменяет любое вхождение первого аргумента вторым аргументом, найденным в третьем аргументе.В этом случае регулярное выражение "^.*description "
соответствует началу $0
, текущей записи (в данном случае запись представляет собой строку ), вплоть до строки description
и заменяя его пустой строкой, удаляя ее, оставляя строку с фактическим описанием.
Последний блок ниже просто печатает строку и FILENAME
, если она находится в диапазоне описания:
{
if (e == 1) {
print FILENAME, $0
}
}
Модификация
Необходимые модификации - это печать FILENAME
в начале диапазона, отступ строк в пределах диапазона и изменение порядка блоков:
# end range
/\]\]/ {
e = 0
}
# in range
e == 1 {
printf "\t%s\n", $0
}
# start range
/description = \[\[/ {
print FILENAME
e = 1
}
Я удалил бесполезные (по крайней мере, для выборочных данных) gsub()
вызов.
Вызов:
$ awk -f script.awk data.txt
Выход:
data.txt
TSO User ID enumerator for IBM mainframes (z/OS). The TSO logon panel
tells you when a user ID is valid or invalid with the message:
<code>IKJ56420I Userid <user ID> not authorized to use TSO</code>.
The TSO logon process can work in two ways:
1) You get prompted with <code>IKJ56700A ENTER USERID -</code>
to which you reply with the user you want to use.
If the user ID is valid it will give you a normal
TSO logon screen. Otherwise it will give you the
screen logon error above.
2) You're given the TSO logon panel and enter your user ID
at the <code>Userid ===></code> prompt. If you give
it an invalid user ID you receive the error message above.
This script relies on the NSE TN3270 library which emulates a
TN3270 screen for NMAP.
TSO user IDs have the following rules:
- it cannot begin with a number
- only contains alpha-numeric characters and @, #, $.
- it cannot be longer than 7 chars