Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

How to replace strings in the last n-lines of multiple files in linux

$
0
0

How can I replace strings in lets say 'last 10 lines' of multiple files?

I have about 100 files with the same extension '.txt' and I would like to replace string 'GLN' to 'LOO' in the last 10 lines of each file. How do I do this? I know how to do it for one file but not for several files.When I use this command ;

for i in `head -3 *.txt  | awk '{print $4}'`     do                   sed -i 's/GLN/LOO/g' *.txt      done

It replaces GLN everywhere it appears in the files and not just the last 10 lines. Please, what am I doing wrong?


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>