Unix/Linux Forum: grep: search for words. - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

grep: search for words. Rate Topic: -----

#1 User is offline   whatever84 

  • User Level: 4/10
  • PipPipPipPip
  • Group: Members
  • Posts: 95
  • Joined: 05-July 06

Posted 12 April 2009 - 11:51 AM

Hello everybody,

I have a file with bulk of data. I need to search for specific pattern, e.g. the below shot shows
a part from the file that contains the words am searching for:

POST Data (example.com): item=car&price=12345&


grep -i "&price="

return the lines that contains "&price="

I don't have much experience in this, but what I am trying to do is to look for the lines that
contain item and price words, and displays the following:

item=car
price=12345
0

#2 User is offline   vibhor_agarwalin 

  • User Level: 7/10
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 574
  • Joined: 24-June 05

Posted 13 April 2009 - 05:20 AM

You can use "cut" with your desired delimeter and parse the line.
Vibhor Kumar Agarwal
0

#3 User is offline   whatever84 

  • User Level: 4/10
  • PipPipPipPip
  • Group: Members
  • Posts: 95
  • Joined: 05-July 06

Posted 13 April 2009 - 08:28 AM

View Postvibhor_agarwalin, on Apr 13 2009, 09:20 AM, said:

You can use "cut" with your desired delimeter and parse the line.


Could you explain further, please? Is cut a different program? or did you mean
to use it in parallel with grep?
0

#4 User is offline   vibhor_agarwalin 

  • User Level: 7/10
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 574
  • Joined: 24-June 05

Posted 17 April 2009 - 09:49 AM

echo 'item=car&price=12345&' | cut -d'=' -f2 | cut -d'&' -f1

Will give you car.
You can construct similar sentences. Yes this will be pre-fixed by grep command as you want to search for "car" & "price"
Vibhor Kumar Agarwal
0

#5 User is offline   vidyadhar 

  • User Level: 1/10
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 01-July 09

Posted 01 July 2009 - 11:01 PM

you can use awk to search them..
awk '/item/&&/price/{print}' filename

and if your pattern is fixed
awk -F"[:&]"  '/item/&&/price/{print $2"\n"$3}' filename

0

#6 User is offline   edidataguy 

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 21-July 09

Posted 23 July 2009 - 08:27 PM

Assuming there is always a space before "price" and there is never space after that.
echo 'POST Data (example.com): item=car&price=12345&' | sed 's/.* \(.*\).$/\1/; s/\&/\n/'

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users