2

How to capture the words in the double quote to one line as 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
  • Is it possible for the double quote to be escaped/backslashed? What output do you expect if there's a non-pair double quote? – choroba Jan 23 '17 at 22:02
  • no backslash before the double quota – yael Jan 23 '17 at 22:05
  • non-pair double not replace the double quota – yael Jan 23 '17 at 22:07
  • Note: a double quota is to be allocated twice as much. – ctrl-alt-delor Jan 23 '17 at 22:14
1

Perl to the rescue:

perl -lne 'print for /"([^"]+)"/g' -- input.txt
2

You could also use grep, e.g.:

grep -o '[^"]\+' input.txt | grep -v '^ *$'

Output:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.