####
yes | head -20 | awk '{printf("HI%02d", NR)}'
####
Delete array[expr] cases array[expr] not to exist.
####
echo abc | mawk { gsub(//, "X") ; print }
XaXbXcX
'Cos if FS="""" (Empty) the awk breaks the record into individual characters.mawk recognizes the empty regular expression, //, which matches the empty string and hence is matched by any string at the front, back and between every character.
####
ls JUNK* | awk '{ print "mv "$0 " ~/tmp/"$0".tmp" }' | bash
mv all files match "JUNK*" to ~/tmp and append '.tmp' to their names.
####
gawk 'BEGIN{RS = "]" ; FS = "["}//[/{print $NF}' testfile
get all section names between [ and ]
本文介绍了如何利用awk工具执行多种文本处理任务,包括文件重命名、字符串替换、记录分割等高级操作。通过具体示例展示了awk的强大功能,如批量重命名匹配特定模式的文件、替换字符串中的字符以及提取文件中指定格式的数据。
654

被折叠的 条评论
为什么被折叠?



