【问题标题】:How to add iterative text at the end of every line of a file using shell script/C/Python? [duplicate]如何使用 shell script/C/Python 在文件的每一行末尾添加迭代文本? [复制]
【发布时间】:2015-04-17 06:04:46
【问题描述】:

目前我有:

a.html
b.html
c.html
d.html
e.html

我想要这个:

a.html 1.css
b.html 2.css
c.html 3.css
d.html 4.css
e.html 5.css

我知道如何在每一行的末尾添加一个文本,例如

awk '{print $0"append_to_end"}' file

但我需要在每一行的末尾添加一个迭代文本(1.css、2.css 等)。如何使用 C 或 Shell 脚本或 Python 做到这一点?我正在使用 Ubuntu。

【问题讨论】:

    标签: python c bash shell unix


    【解决方案1】:

    您可以使用awk 来做到这一点。基本上就是这样。

    awk '{print $0 ++i".css"}' file
    

    【讨论】:

    • 谢谢,但我已经有了“文件”。如何将此结果附加到文件中的每一行?
    • 好的,解决了,谢谢!
    猜你喜欢
    • 2018-03-20
    • 2013-04-05
    • 2014-08-22
    • 2017-12-02
    • 1970-01-01
    • 2012-07-03
    • 2014-05-29
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多