Hi
I am struggling to find a solutions to this problem:
I have a directory full of files and I wish to:
read each line of each file and
if any one line in those files is longer than 72 characters I want to replace any tab characters with a space character.
Ive been researching/testing sed and awk but cant get anything working in this manner.
Any help would be greatly appreciated.
Thanks!
Something like this?
awk 'length > 72 {gsub("\t"," ")}1' file
1 Like
Exactly like that Thanks very much!
I'm new to all this, I appreciate the help.
How do I make those changes to the file itself rather than printing the formatted text to the screen?
You can't edit files in place with awk, use a temporary file:
awk 'length > 72 {gsub("\t"," ")}1' file > tempfile
mv tempfile file
or maybe with something like:
awk 'length > 72 {gsub("\t"," ")}{print > "tempfile"}
END{system("mv tempfile file")}' file