Tom*_*isi 172
如果您sed允许通过-i参数进行编辑:
sed -e 's/$/string after each line/' -i filename
如果没有,你必须制作一个临时文件:
typeset TMP_FILE=$( mktemp )
touch "${TMP_FILE}"
cp -p filename "${TMP_FILE}"
sed -e 's/$/string after each line/' "${TMP_FILE}" > filename
Opt*_*ime 12
我更喜欢使用awk.如果只有一列,请使用$0,否则将其替换为最后一列.
单程,
awk '{print $0, "string to append after each line"}' file > new_file
或这个,
awk '$0=$0"string to append after each line"' file > new_file
欢乐的*_*aox 11
我更喜欢echo。使用纯 bash:
cat file | while read line; do echo ${line}$string; done
如果你有它,lam(层压板)实用程序可以做到这一点,例如:
$ lam filename -s "string after each line"
纯POSIX 外壳和sponge:
suffix=foobar
while read l ; do printf '%s\n' "$l" "${suffix}" ; done < file | 
sponge file
xargs和printf:
suffix=foobar
xargs -L 1 printf "%s${suffix}\n" < file | sponge file
使用join:
suffix=foobar
join file file -e "${suffix}" -o 1.1,2.99999 | sponge file
使用paste, yes, head
& 的Shell 工具wc:
suffix=foobar
paste file <(yes "${suffix}" | head -$(wc -l < file) ) | sponge file
请注意,在 之前paste插入一个Tab字符$suffix。
当然sponge可以用临时文件替换,然后替换mv原始文件名,就像其他一些答案一样......