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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting a row block one by one in a file

Status
Not open for further replies.

sansun

Technical User
Jul 27, 2005
2
IN
file.xml :

<ROW>
<TARGET_GUID>21CFE36DC1C2A7C7735A6DA806D02F1D</TARGET_GUID>
<COLLECTION_TIMESTAMP>2005-07-27 06:20:53</COLLECTION_TIMESTAMP>
<USER_NAME>root</USER_NAME>
<USER_ID>0</USER_ID>
<DEFAULT_SHELL>/bin/bash</DEFAULT_SHELL>
</ROW>
<ROW>
<TARGET_GUID>21CFE36DC1C2A7C7735A6DA806D02F1D</TARGET_GUID>
<COLLECTION_TIMESTAMP>2005-07-27 06:20:53</COLLECTION_TIMESTAMP>
<USER_NAME>bin</USER_NAME>
<USER_ID>1</USER_ID>
<DEFAULT_SHELL>/sbin/nologin</DEFAULT_SHELL>
</ROW>
<ROW>
<TARGET_GUID>21CFE36DC1C2A7C7735A6DA806D02F1D</TARGET_GUID>
<COLLECTION_TIMESTAMP>2005-07-27 06:20:53</COLLECTION_TIMESTAMP>
<USER_NAME>daemon</USER_NAME>
<USER_ID>2</USER_ID>
<DEFAULT_SHELL>/sbin/nologin</DEFAULT_SHELL>
</ROW>
<ROW>
<TARGET_GUID>21CFE36DC1C2A7C7735A6DA806D02F1D</TARGET_GUID>
<COLLECTION_TIMESTAMP>2005-07-27 06:20:53</COLLECTION_TIMESTAMP>
<USER_NAME>adm</USER_NAME>
<USER_ID>3</USER_ID>
<DEFAULT_SHELL>/sbin/nologin</DEFAULT_SHELL>
</ROW>

I want to read/extract the contents within <ROW> and </ROW> one by one at a time.

first read/extract contents within first row block and then second and then third and so on...


I donot want extract all column names of a file at one shot.

any help will be greatly appreciated.

Rgds,
Sansun

 
hi guys,
reply to my post.

I am need of solution.

 
Code:
/<ROW>/ { next }
/<\/ROW>/ { print ""; next }
{ gsub(/^[ \t]*<|<[^>]*>$/, "")
  sub(/>/, ": ")
  print }
Save as x.awk and run with[tt]
awk -f x.awk infile >outfile[/tt]
 
Hi

Sometimes could be easyer with [tt]csplit[/tt] ( split a file into sections determined by context lines - man ). This will split your above sample puting each section in separate file :

Code:
csplit file.xml -z '/<ROW>/' '{*}'

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top