Sed 如何放置带有退格和单词的单词?

Sed 如何放置带有退格和单词的单词?,sed,vim,Sed,Vim,我有一个包含以下行的文本文件: telephone xxxx telpassword xxxx telephone xxxx telpassword xxxx telephone xxxx telpassword xxxx telephone xxxx telpassword xxxx telephone xxxx telpassword xxxx telephone xxxx telpassword xxxx 我想让一个文件包含相同的数据,但在行中: telephone xxxx telpa

我有一个包含以下行的文本文件:

telephone xxxx
telpassword xxxx
telephone xxxx
telpassword xxxx
telephone xxxx
telpassword xxxx
telephone xxxx
telpassword xxxx
telephone xxxx
telpassword xxxx
telephone xxxx
telpassword xxxx
我想让一个文件包含相同的数据,但在行中:

telephone xxxx telpasswordxxxx
telephone xxxx telpasswordxxxx
telephone xxxx telpasswordxxxx
telephone xxxx telpasswordxxxx
telephone xxxx telpasswordxxxx
我试过:

sed 's/telpassword/\btelpassword/g'
但是这个命令不起作用。我认为应该是这样的,但我不知道如何将“backspace”命令放在那里

感谢您的帮助。

发件人:

使用awk:

awk '!(NR%2){print p " " $0}{p=$0}' filename
发件人:

使用awk:

awk '!(NR%2){print p " " $0}{p=$0}' filename
使用

script.vim的内容

set backup
g/^telephone/ normal J
saveas! output.txt
q!
像这样运行:

vim -u NONE -N -S script.vim infile
它将创建一个包含以下内容的文件
output.txt

telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
使用

script.vim的内容

set backup
g/^telephone/ normal J
saveas! output.txt
q!
像这样运行:

vim -u NONE -N -S script.vim infile
它将创建一个包含以下内容的文件
output.txt

telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
telephone xxxx telpassword xxxx
这应该起作用:

 awk '/tele/{printf "%s ",$0}/telp/{print $0}' inputFile
这应该起作用:

 awk '/tele/{printf "%s ",$0}/telp/{print $0}' inputFile
使用粘贴:

paste -d" " - - < filename
paste-d”“-
使用粘贴:

paste -d" " - - < filename
paste-d”“-
Hello Birei,我使用的是solaris 8,没有vim。能否请您将此脚本调整为.sh或.ksh?Thanks@VulturuStefan这些是不同的东西。使用其他答案的解决方案,无论是
sed
还是
awk
都可以。您好,Birei,我使用的是solaris 8,我没有vim。能否请您将此脚本调整为.sh或.ksh?Thanks@VulturuStefan这些是不同的东西。使用其他答案的解决方案,无论是
sed
还是
awk
都可以。您好,sed命令正在工作,但我认为我的文件中有一些行是空的,您可以将sed命令调整为字符串“telpassword”或“telephone”?在命令之前添加
grep tel |
。别忘了添加
|
。您好,sed命令正在工作,但我认为我的文件中有一些行是空的,您可以将sed命令调整为字符串“telpassword”或“telephone”?在命令之前添加
grep tel |
。不要忘记添加
|