Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from file

Status
Not open for further replies.

mrcuser

Technical User
Aug 26, 2008
22
GB
Hi I have a file that has data throughout the file but the lines i want to pull out look like this:

\\node_name\c- ACTIVE_VERSION DIR \ 351134684 XCHG_3MTH
$\bo_unts\stg_-
file_mb1_sg1-
_mb1
anythin\relevantdrive
\\node_name\c- ACTIVE_VERSION FILE \RECYCLER\S-2-3-4- INFO2 2008-08-13
$\bo_unts\stg_- 04:28:04.000000
exchange_mb5_sg5-
_mb3 9-1106\

As you can see the data is truncated and hangs onto 4 extra lines from the first column i.e the first line should be
\\node_name\c$\bo_unts\stg_file_mb1_sg1_mb1 then active version etc

Therefore I want to use AWK to go through the file and extract the 5 lines (in total) so it'd read from the \\node_name as its first line then count down 4 lines.

Really bad explanation but all I need from the file is all the lines under node_name including the node_name line.




 

Try this:
Code:
awk '/\\node_name\\/ {
if (sw==1) print l0; 
l0="";sw=0;
} 
{l0=l0$0;sw=1;}
END {print l0;}
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks for the reply but forgive me for my ignorance, how do I run that over my file ?

I've tried to cat the file but at the end of the awk statement it keep displaying >
 
Hi

A single quote ( ' ) disappeared from the end probably when LKBrwnDBA copy & pasted the code.
Code:
awk '/\\node_name\\/ {
if (sw==1) print l0;
l0="";sw=0;
}
{l0=l0$0;sw=1;}
END {print l0;}[red][b]'[/b][/red] /input/file

Feherke.
 
Great that does near enough what I need - hell of a lot better than anything i've tried I can modify it now hopefully to get what I need.

Thanks very much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top