开发者

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

开发者 https://www.devze.com 2022-12-20 20:05 出处:网络
is there any shell command to insert a string of characters in every 开发者_StackOverflowline of a file..

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


Lots of them.

This will work:

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


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


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


awk

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

精彩评论

暂无评论...
验证码 换一张
取 消