Issue
I'm pretty unfamiliar with awk
, but I am looking for a way to iterate through all files in a directory and execute a simple awk
command. My command is a simple substitution that replaces all tabs with two spaces.
awk '{gsub("\t"," ");print}'
How can this be extended to loop through a directory and execute the command on all files?
Solution
Pass the files to awk on the command line of course:
$ awk 'program' *
But probably it is easier to use
$ perl -pe 's/\t/ /g' *
Or, if you would rather have an in place edit, simply:
$ perl -i.orig -pe 's/\t/ /g' *
Answered By - tchrist Answer Checked By - Timothy Miller (WPSolving Admin)