Monday, May 13, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1355  / 2 Years ago, wed, december 8, 2021, 7:33:01

I have many text files in a directory. I want to append/add * at the end of last line (content) of each and every text file of the directory with the extension .txt
How can this be achieved in Ubuntu 20.10 in single operation?


Why I am asking this is because currently I am working on .txt and .pgn files.
If I have to convert .txt to .pgn file then an *, 1/2-1/2, 1-0 or 0-1 is needed at the end of the last line, (signifying score or end of game to the machine) otherwise I will not be able to convert them to .pgn files. Also even if I convert them to .pgn files by save as, then also the file would still be incomplete and unreadable in machine binary that will be made out of it. Machine will not be able to identify it as a score or end.


More From » command-line

 Answers
6

This one should be able to do it to all your .txt files.


Run from the current folder that all your .txt files are in:


find . -maxdepth 1 -iname "*.txt" -print0 | xargs -L1 -0 sed -i '$a*'

That command will find all files even with spaces then append a * to the last line of all the .txt files found in that folder.


Hope this helps!


[#1932] Wednesday, December 8, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wheance

Total Points: 314
Total Questions: 96
Total Answers: 112

Location: Benin
Member since Thu, Aug 12, 2021
3 Years ago
;