text processing - How to remove last character from grep output? -
i have text file following content in (for example):
in first line "one", second"two " & " 3 " , also"four ". in second line nested "foo "bar" baz""zoo" patterns.
i tried had strings between pair of quotes , ended command:
grep -po '"\k[^"]+"' file
what command gave me following:
one" 2 " 3 " 4 " foo " baz" zoo"
and what want above result desired output be:
one 2 3 4 foo baz zoo
please me remove last "
above grep
output. don't want remove spaces output. don't have words expanded multiline. e.g:
... "foo "bar" ba z""zoo" ...
please, please don't suggest me can use multiple commands, know can. i'm ask if can grep , options alone?
this possible through below grep one-liner.
$ grep -op '"\k[^"]+(?="(?:[^"]*"[^"]*")*[^"]*$)' file 1 2 3 4 foo baz zoo
another hacky 1 through pcre verb (*skip)(*f)
,
$ grep -op '[^"]+(?=(?:"[^"]*"[^"]*)*[^"]*$)(*skip)(*f)|[^"]+' file 1 2 3 4 foo baz zoo
Comments
Post a Comment