shell - How to add text at the end of each line in unix -


i doing text processing operations , able file this

india sudan japan france 

now want add comment in above file in final file should

india | country sudan | country japan | country france | country 

like same comment across whole file. how do this?

there many ways:

sed: replace $ (end of line) given text.

$ sed 's/$/ | country/' file india | country sudan | country japan | country france | country 

awk: print line plus given text.

$ awk '{print $0, "| country"}' file india | country sudan | country japan | country france | country 

finally, in pure bash: read line line , print given text. note discouraged explained in why using shell loop process text considered bad practice?

$ while ifs= read -r line; echo "$line | country"; done < file india | country sudan | country japan | country france | country 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -