acctman
acctman

Reputation: 4349

grep command line, linux

i'm trying to isolate all the server names (i.e sv012-cali) from within an html file "Servernick":"sv012-cali" in the line code below I think its the quotation mark that's throwing it off

cat smtest.html | tr '"' '\n' | grep "^Servernick":"" | cut -d '"' -f 2

snippet of the html data file "Relation":0},{"ID":415804","Servernick":"sv012-cali","Level":"3"

Upvotes: 0

Views: 515

Answers (3)

Darth Ninja
Darth Ninja

Reputation: 1039

Updated after OP provided sample data -

# cat test.data                                                  
"Relation":0},{"ID":415804","Servernick":"sv012-cali","Level":"3"
"Relation":0},{"ID":415804","Servernick":"sv012-balh","Level":"3"
# cat test.data | tr "," "\n" | grep Servernick | cut -d '"' -f 4
sv012-cali
sv012-balh

Original reply -

Is this what you need?

# echo \"Servernick\":\"sv012-cali\"  > test.data  
# cat test.data                                  
"Servernick":"sv012-cali"
# cat test.data  | tr '"' '\n'                                          

Servernick
:
sv012-cali

# cat test.data  | tr '"' '\n' | egrep -v "Servernick|:|^$"
sv012-cali

Upvotes: 1

sfk
sfk

Reputation: 709

Use single quote when dealing with strings containing double quotes :

grep '^Servernick":"'

Upvotes: 2

peoro
peoro

Reputation: 26060

You need to escape the quotes. In bash use \ to escape characters:

grep "^Servernick\":\""

or alternatively put your double quotes within single quotes:

grep '^servernick":"'

Upvotes: 2

Related Questions