使用Shell脚本将后缀添加到每一行 [英] Add suffix to each line with shell script

查看:204
本文介绍了使用Shell脚本将后缀添加到每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文本文件的每一行末尾添加一些单词.如何使用Bash脚本执行此操作?

I need to add some words at the end of each line of a text file. How can I do this with a Bash script?

示例:在每行的末尾添加单词done:

Example: add the word done at the end of each line:

line1 abcdefg done
line2 abcdefg done
line3 abcdeft done

推荐答案

使用awk:

awk 'NF{print $0 " done"}' inFile

或使用内联标志进行sed

OR sed with inline flag:

sed -i.bak '!/[^[:blank:]]/s/$/ done/' inFile

这篇关于使用Shell脚本将后缀添加到每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆