Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing verbose progress from sed and awk

Tags:

sed

awk

The programs sed and awk usually does their work quietly. Is there any way to get these programs to state what they are doing?

like image 907
Village Avatar asked Mar 23 '12 03:03

Village


People also ask

Can I use awk and sed together?

Combining the Twoawk and sed are both incredibly powerful when combined. You can do this by using Unix pipes.

How do I see grep progress?

In recent versions of pv there is an "-d" -Option to watch all the FDs of another process. For the Problem above a simpler idea is the following: While the grep is running, use lsof together with watch . That way you can monitor the progress of your grep.

Is awk or sed faster?

I find awk much faster than sed . You can speed up grep if you don't need real regular expressions but only simple fixed strings (option -F). If you want to use grep, sed, awk together in pipes, then I would place the grep command first if possible.

Should I use sed or awk?

Conclusion: Use sed for very simple text parsing. Anything beyond that, awk is better. In fact, you can ditch sed altogether and just use awk. Since their functions overlap and awk can do more, just use awk.


2 Answers

This is based on potong's answer. The following code replaces 'll' with 'zz', creates a backup file, displays the new text, and writes the change(s) into the file.

$ echo hello > test $ sed -e 's/ll/zz/;w /dev/stdout' -i .backup test hezzo $ cat test hezzo $ cat test.backup  hello 
like image 166
Paul Avatar answered Sep 23 '22 05:09

Paul


On the assumption that you are piping your sed output to a file, you could use the tail command (in another terminal) to constantly look at the end of file; such that you could see the progress.

tail -f output_from_sed.txt 
like image 27
amasmiller Avatar answered Sep 20 '22 05:09

amasmiller