Pages

lundi 22 octobre 2012

add characters in the beginning/end of each line


---- add "\hline" in the begining of each line in a file one_year_stat
sed 's/^/ \\hline /' one_year_stat  > tt

---- add "\" in the end of each line in a file:
sed 's/$/ \\/'    tt 


---- add " &" in the end of each line in a file:
sed 's/$/  \&/'   tt

---- replace the last occurence of & in each line of a file with a space:

sed 's /\(.*\)& /\1 /' one_year_stat


-----If the new text contains "/", eg a path /home/user/tt, then the sed 's/../g' does not work. We should use "|" instead of "/"
set aa = /home/user/tt
sed   "s|^|${aa}|g"    txt_file 


NOTE: For special characters such as \ or &;, if we want to add then in the text file using the sed. We need put \ before them such that they may be added in the file.

Aucun commentaire:

Enregistrer un commentaire