Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add suffix to each line with shell script

Tags:

linux

bash

shell

I need to add some words at the end of each line of a text file. How can I do this with a Bash script?

Example: add the word done at the end of each line:

line1 abcdefg done
line2 abcdefg done
line3 abcdeft done
like image 478
Bing.Physics Avatar asked Jun 07 '13 18:06

Bing.Physics


2 Answers

Use awk:

awk 'NF{print $0 " done"}' inFile

OR sed with inline flag:

sed -i.bak '!/[^[:blank:]]/s/$/ done/' inFile
like image 51
anubhava Avatar answered Sep 19 '22 13:09

anubhava


Did I read vim?

Content of script.vim:

set backup
g/^/ normal A done
normal ZZ

Run it like:

vim -S script.vim infile

It will modify the file in-place creating a backup with ~ suffix.

like image 30
Birei Avatar answered Sep 21 '22 13:09

Birei