如何将双引号中的单词捕获到一行作为out.txt
more input.txt
"OQ -63/ECC/UK/JDA/adRedprairie" "OQ -63/ECC/UK/JDA/adRedprairie.ear" "OQ- 63/ECC/UK/JDA/adRedprairie.xml"
"OQ/CZ/Ecomphos/216_06/OM-S03" "OQ/CZ/Ecomphos/216_06/OM-S03.ear" "OQ/CZ/Ecomphos/216_06/OM-S03.xml"
more out.txt
OQ -63/ECC/UK/JDA/adRedprairie
OQ -63/ECC/UK/JDA/adRedprairie.ear
Q-63/ECC/UK/JDA/adRedprairie.xml
OQ/CZ/Ecomphos/216_06/OM-S03
OQ/CZ/Ecomphos/216_06/OM-S03.ear
OQ/CZ/Ecomphos/216_06/OM-S03.xml
答案1
您也可以使用grep
,例如:
grep -o '[^"]\+' input.txt | grep -v '^ *$'
输出:
OQ -63/ECC/UK/JDA/adRedprairie
OQ -63/ECC/UK/JDA/adRedprairie.ear
OQ- 63/ECC/UK/JDA/adRedprairie.xml
OQ/CZ/Ecomphos/216_06/OM-S03
OQ/CZ/Ecomphos/216_06/OM-S03.ear
OQ/CZ/Ecomphos/216_06/OM-S03.xml
答案2
Perl 来拯救:
perl -lne 'print for /"([^"]+)"/g' -- input.txt