views:

104

answers:

4

He is a nice guy. "Rob" doesn't like it though.

How to extract Rob from this line using shell script?

+2  A: 

This is a way of doing it, the first that came to my mind:

echo "He is a nice guy. \"Rob\" doesn't like it though" | cut -d'"' -f2

Of course it could have been done with sed or awk.

Is this homework?

Alberto Zaccagni
na, its not homework.was trying out a script
Abhijeet
+1  A: 
$ echo "He is a nice guy. \"Rob\" doesn't like it though." | gawk -F'"' '{print $2}'
Rob
ghostdog74
A: 

you can just use the shell

$ string="He is a nice guy. \"Rob\" doesn't like it though."
$ string=${string#*\"}
$ echo ${string%%\"*}
Rob
A: 

Here is another solution, try this

echo "ROB" | tr ""''

The first two "" are double quotes and the last two are single quotes

Sachin Chourasiya