This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Get the exact string - not the entire line using grep
yuga devi
Greenhorn
Joined: Aug 07, 2008
Posts: 22
posted
0
Hi,
Is there any command in unix, to grep the exact word from a file, not the entire line. I have tried using grep -w, but it returns the entire line.
For ex, my file consists of
Log14534|0A353C0B.4A9282E3.00012623.00002EBE|[color=red]123456789|START TRANSACTION|host1|Mon Aug 24 08:56:27 EDT 2009|[/color]
In this, i want to grep, dynamically passing the unique no "123456789" and need to ge the word, "START TRANSACTION".
Please help.
-- Yuga
yuga devi
Greenhorn
Joined: Aug 07, 2008
Posts: 22
posted
0
Hi, -sorry for the confusion in the highlighted color
Is there any command in unix, to grep the exact word from a file, not the entire line. I have tried using grep -w, but it returns the entire line.
For ex, my file consists of
Log14534|0A353C0B.4A9282E3.00012623.00002EBE|123456789|START TRANSACTION|host1|Mon Aug 24 08:56:27 EDT 2009|
In this, i want to grep, dynamically passing the unique no "123456789" and need to ge the word, "START TRANSACTION".
Please help.
-- Yuga
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35247
7
posted
0
grep is line-oriented - it can't return partial results. But you can pipe its output into another tool -like sed or awk- that can extract parts of lines.