In each line of the file, the fields are separated by ^K.
I only want to remove '&' if it exists in field number 9. (example of field 9: abc&xyz)
I need to do an in place/in line edit.
In the above line - awk gets the field 9
- filtering using grep and only looking for field 9 with '&'
- sed removes the '&' from the field and sends output to log file (input file is untouched).
But, I want the input file itself to be edited. I dont need a log file.
Any other options or suggestions will be helpful.
Thank you
The content of the input file becomes stdin for rm and awk,
rm ignores it and removes the file, but its file descriptor remains open until both commands (rm and awk) complete, so awk process this "nameless" file and creates a new file.
sub removes (replaces with "") the first occurrence of & in the 9th field (use gsub for global substitution or GNU Awk's gensub for more articulated substitutions).
1 is just a shortcut, it means print the current record;
it can be explained like this:
1!=0 -> true -> use default action -> print $0
FS and OFS are treated differently, so in the first case we have to escape the ^ character.