1

I am new to Unix commands. I would just like to ask if adding a tab or should i say multiple spaces right after at the end of each line in Unix is possible?

To give a clearer view of what i am talking about, Supposed i have a text file named WOW.txt and it contains: (Note that WOW.txt is a product from a script that i run. So it is automatically made by a a script)

Wow

Wow2

Wow3

Wow4

And i want to add tabs at each end of line. This is how i want to be an output.

Wow1 KERV

Wow2 KERV

Wow3 KERV

Wow4 KERV

or

Wow1, KERV

Wow2, KERV

Wow3, KERV

Wow4, KERV

Thats i want to be an output. I just want to add the word 'KERV' at each end of a line on my text file. So please somebody help me???

A reply from you would be greatly appreciated. Thanks!!!!

4

2 回答 2

1

您可以使用sed要添加的任何内容替换行尾 ( $)。这将使换行符保持$为零宽度。

于 2013-05-06T04:38:31.980 回答
0

您可以使用以下AWK脚本。 awk '{printf("%s \t\n", $0)}' your_file.txt > new_file.txt

请注意,\t添加TABS. 如果你想要多个标签,你可以做\t\t并且\n是一个newline字符

如果您想添加KERV或其他任何内容,请适当添加,例如"%s, \t KERV : \t\t\n 如果您不想要旧文件,只需执行rm your_file.txt

编辑:如果链接为空,请使用以下内容不向链接附加任何内容-

awk '{ if (NF > 0) { printf("%s \t\n", $0)} }' your_file.txt > new_file.txt

编辑:如果你想保留空行,但不附加任何东西

awk '{ if (NF > 0) {printf("%s \t\n", $0)} else {print $0} }' your_file.txt > new_file.txt

于 2013-05-06T04:27:25.087 回答