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开发者_StackOverflow中文版 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"
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":"'
Use single quote when dealing with strings containing double quotes :
grep '^Servernick":"'
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
精彩评论