0

I have multiple tab delimited files with same column names. An example file is attached as a snapshot.

enter image description here

Now, I would like to replace every 'INV' in coloumn 4 with 'RAC'. I wrote the following awk code. However it does not work well. Can anyone check my code?

#!/bin/bash
path=path/to/dir/containing/the/files/to/be/processed
for file in `ls $path`
do
echo processing $file
awk '{ if ($4 == "INS") {$4 = "RAC"; print} else { print }; }'  $file>  ${file}_new.txt
done;
2

1 Answer 1

1

Do not parse ls output as shown [ here ].

find /path/to/files -maxdepth 1 -type f -print0 | while read -r -d '' filename
do
awk '$4=="INV"{$4="RAC"}{print}' "$filename" > tempfile && mv tempfile "$filename"
done

would do it

Sign up to request clarification or add additional context in comments.

2 Comments

@123 : Indeed.. Corrected that
Thanks! It worked now. I appreciate the suggestions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.