trinity
trinity

Reputation: 10484

is there a shell command to insert a string of characters in every line of a file

is there any shell command to insert a string of characters in every line of a file.. < in the beginning or the end of every line >

Upvotes: 0

Views: 2181

Answers (4)

ghostdog74
ghostdog74

Reputation: 342759

awk

awk '{print NR"START"$0"END"}' file

Upvotes: 0

dubiousjim
dubiousjim

Reputation: 4822

linecount=0
while IFS= read -r LINE; do
  echo "$((linecount++)) START $LINE END"
done < file

If you want to do fancier manipulation of the linecount:

linecount=0
while IFS= read -r LINE; do
  let linecount++
  echo "$((linecount-5)) START $LINE END"
done < file

Upvotes: 0

John Kugelman
John Kugelman

Reputation: 361937

sed -i 's/^/Before/' file.txt
sed -i 's/$/After/'  file.txt

Upvotes: 3

dubiousjim
dubiousjim

Reputation: 4822

Lots of them.

This will work:

sed -i -e 's/.*/START & END/' file

Upvotes: 6

Related Questions