Bha*_*wan 5 linux bash awk sed
我有一个带有'|| o ||'的示例文件 作为字段分隔符.
www.google.org||o||srScSG2C5tg=||o||bngwq
farhansingla.it||o||4sQVj09gpls=||o||
ngascash||o||||o||
ms-bronze.com.br||o||||o||
Run Code Online (Sandbox Code Playgroud)
我想移动只有1个字段的行和有1 1.txt个以上字段的行not_1.txt.我使用以下命令:
sed 's/\(||o||\)\+$//g' sample.txt | awk -F '[|][|]o[|][|]' '{if (NF == 1) print > "1.txt"; else print > "not_1.txt" }'
Run Code Online (Sandbox Code Playgroud)
问题是它不是原始线而是移动线.
我得到的输出是(not_1.txt):
td@the-end.org||o||srScSG2C5tg=||o||bnm
erba01@tiscali.it||o||4sQVj09gpls=
Run Code Online (Sandbox Code Playgroud)
1.TXT:
ngas
ms-inside@bol.com.br
Run Code Online (Sandbox Code Playgroud)
如您所见,原始线条已被修改.我不想修改这些行.任何帮助将受到高度赞赏.
Awk解决方案:
awk -F '[|][|]o[|][|]' \
'{
c = 0;
for (i=1; i<=NF; i++) if ($i != "") c++;
print > (c == 1? "1" : "not_1")".txt"
}' sample.txt
Run Code Online (Sandbox Code Playgroud)
结果:
$ head 1.txt not_1.txt
==> 1.txt <==
ngascash||o||||o||
ms-bronze.com.br||o||||o||
==> not_1.txt <==
www.google.org||o||srScSG2C5tg=||o||bngwq
farhansingla.it||o||4sQVj09gpls=||o||
Run Code Online (Sandbox Code Playgroud)