Hi,
my input
abc def "."; ghi
abc kgk mhi def "="; klm nop
abc kgg def "j"; klm mno pwd rst
I would like to get the content in the inverted commas after def. So, my output would be
.
=
j
How do I do it? Please make a note that my input field separator is space and not tab.
Thanks
Hi
$ cut -d\" -f2 file
.
=
j
Guru.
1 Like
joeyg
June 1, 2012, 10:34am
3
$ sed 's/def /def~/g' <sample10.txt | tr " " "\n" | grep "^def" | cut -c6
.
=
j
Hi guru,
Thanks for ur reply.
I just found out that the end portion of my file contains records that are in inverted commas.
abc def "."; ghi
abc kgk mhi def "="; klm nop
abc kgg def "j"; klm mno pwd rst
abc def "="; osr ">"; kil bil wil
fgh osr "{"; gik hik juy def "*";
my output now will be
.
=
j
=
*
Sorry for any inconvenience.
joeyg
June 1, 2012, 10:39am
5
Do you mean quotes "
Also, sometimes referred to as double-quotes so as not to be confused with the single-quote symbol '
yes, double quotes.
And also, the sed script is printing hyphens.
My def column is changing across the entire file.
Thanks for ur time.
joeyg
June 1, 2012, 11:18am
7
Not sure what is printing hyphens. See below.
$ cat sample10.txt
abc def "."; ghi
abc kgk mhi def "="; klm nop
abc kgg def "j"; klm mno pwd rst
$ cat sample11.txt
abc def "."; ghi
abc kgk mhi def "="; klm nop
abc kgg def "j"; klm mno pwd rst
abc def "="; osr ">"; kil bil wil
fgh osr "{"; gik hik juy def "*";
$ sed 's/def /def~/g' <sample10.txt | tr " " "\n" | grep "^def" | cut -c6
.
=
j
$ sed 's/def /def~/g' <sample11.txt | tr " " "\n" | grep "^def" | cut -c6
.
=
j
=
*
i am not good with sed or awk , but we can implement something with this regex
("[^"]")
with use of some back reference feature.
Again , if i am wrong , please correct me
---------- Post updated at 01:19 PM ---------- Previous update was at 10:25 AM ----------
[^a-z ;"]
this regex matches only the special character. But dont know how to implement it to extract only the special character. Some help , would be much appreciated
Hi,
my input
abc def "."; ghi
abc kgk mhi def "="; klm nop
abc kgg def "j"; klm mno pwd rst
I have changed my output content which would be 3 separate files.
The rows with def "." will go into file by name dot.txt
And, the rows with def "=" will go into a file by name equal.txt
And the rows with def "j" will go into a file by name jack.txt
The remaining records should go into a file by name remaining.txt
How do I do it? Please make a note that my input field separator is space and not tab.
Thanks in advance
cabrao
June 7, 2012, 12:59pm
10
Not pretty, but should fit your request
awk '/\"\.\"/{print>"dot.txt"};/\"=\"/{print>"equal.txt"};/\"j\"/{print>"jack.txt"};!/\"[\.=j]\"/{print>"remaining.txt"}' inputfile
1 Like
cabrao:
Not pretty, but should fit your request
awk '/\"\.\"/{print>"dot.txt"};/\"=\"/{print>"equal.txt"};/\"j\"/{print>"jack.txt"};!/\"[\.=j]\"/{print>"remaining.txt"}' inputfile
Hi cabrao,
Thanks for your response.
The code should consider the letters def before the quotes too.
How do I append it?