我有一个文本文件,其中包含如下代码行:
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“命令。
谢谢你的帮助。
发布于 2013-06-20 21:34:21
来自sed one liners
sed '$!N;s/\n/ /' inputfile使用awk:
awk '!(NR%2){print p " " $0}{p=$0}' filename发布于 2013-06-20 22:04:03
这应该是可行的:
awk '/tele/{printf "%s ",$0}/telp/{print $0}' inputFile发布于 2013-06-20 21:48:41
使用vim
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 xxxxhttps://stackoverflow.com/questions/17214940
复制相似问题