scanf,back reference in awk
Is there any implementation of scanf()(like in C) in awk(POSIX)?
I know that awk does n开发者_运维技巧ot have back reference like in sed and perl. What is the easiest way to simulate in awk?
Thanks
Nyan
sprintf() , printf() may be what you are looking for. awk does not support backreferences however gawk's gensub(), or even gsub() can provide backreferences.
Backreferences are just storing the strings that are matched. So, making use of awk's capability to differentiate fields and field delimiters, using its internal variables like OFS,FS,ORS etc are the way to go.. eg
$ echo "test.txt" | sed 's/\(.*\).txt/\1.pdf/'
test.pdf
$ echo "test.txt" | awk -F"." '{$NF="pdf"}1' OFS="."
test.pdf
Of course, this is just a simple example. But you get the idea.
精彩评论