Is there any implementation of scanf()(like in C) in awk(POSIX)?
I know that awk does not have back reference like in sed and perl. What is the easiest way to simulate in awk?
Thanks
Nyan
Is there any implementation of scanf()(like in C) in awk(POSIX)?
I know that awk does not 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.