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 开发者_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
精彩评论