开发者

scanf,back reference in awk

开发者 https://www.devze.com 2023-01-09 02:16 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消