这是我的行。
2706 abc/efe/efefe/fefe 10143 fefef/dbddf/fvfvdf/vdfvdp 8927 fvdfv/fvdv/fvdfv/fvdfv 11546 fvsddfv/fdfvdv/fvddffv/fvddfv
预期产出
2706 abc/efe/efefe/fefe
10143 fefef/dbddf/fvfvdf/vdfvdp
8927 fvdfv/fvdv/fvdfv/fvdfv
.
.
.
.
11546 fvsddfv/fdfvdv/fvddffv/fvddfv
答案 0 :(得分:4)
如果你的行的格式是固定的,你可以试试这行:
cat file|xargs -n2
使用您的示例进行测试:
kent$ cat f
2706 abc/efe/efefe/fefe 10143 fefef/dbddf/fvfvdf/vdfvdp 8927 fvdfv/fvdv/fvdfv/fvdfv 11546 fvsddfv/fdfvdv/fvddffv/fvddfv
kent$ cat f|xargs -n2
2706 abc/efe/efefe/fefe
10143 fefef/dbddf/fvfvdf/vdfvdp
8927 fvdfv/fvdv/fvdfv/fvdfv
11546 fvsddfv/fdfvdv/fvddffv/fvddfv
答案 1 :(得分:1)
使用GNU awk进行多字符RS:
$ awk -v RS='\\s' '{ORS=(NR%2?" ":"\n")}1' file
2706 abc/efe/efefe/fefe
10143 fefef/dbddf/fvfvdf/vdfvdp
8927 fvdfv/fvdv/fvdfv/fvdfv
11546 fvsddfv/fdfvdv/fvddffv/fvddfv
有些(大多数?)seds:
$ sed -r 's/([^ ]+ +[^ ]+) +/\1\n/g' file
2706 abc/efe/efefe/fefe
10143 fefef/dbddf/fvfvdf/vdfvdp
8927 fvdfv/fvdv/fvdfv/fvdfv
11546 fvsddfv/fdfvdv/fvddffv/fvddfv
答案 2 :(得分:0)
在每个数字序列后面插入换行符,后跟一串非数字字符:
sed 's/\([0-9]* [^0-9]*\) /\1\n/g' input
或用换行符替换非数字字符后的空格:
sed 's/\([^0-9]\) /\1\n/g' input
给出:
2706 abc/efe/efefe/fefe
10143 fefef/dbddf/fvfvdf/vdfvdp
8927 fvdfv/fvdv/fvdfv/fvdfv
11546 fvsddfv/fdfvdv/fvddffv/fvddfv
答案 3 :(得分:0)
你可以使用sed,
sed 's/[[:blank:]]\+\([0-9]\+\)/\n\1/g' file
通过grep,
grep -oP '\d+\s+\S+' file