- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Awk and rss feeds: awk question:
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:05 AM
12-14-2005 06:05 AM
I'm trying to parse some files from a shell script. The general structure of the file is:
..../snip/...
stuff
yada yada yada
....
blah
.. and so forth...
I want to extract stuff between lines that begin with
I've this so far:
cat in.file | awk '/^
getline;
while ( $0 !~ "^<\/item>" ) {
print $0
getline;
}
exit ;
}' >> /tmp/out.$$
This extracts only the 1st section of infile between
Now, without "exit;", it extracts all sections in infile which start and end with
Any help will be much appreciated.
--AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:57 AM
12-14-2005 06:57 AM
Re: Awk and rss feeds: awk question:
awk -f awkprog in.file
awkprog contains-
/^
/^<\/item>/{ITEM=0};
ITEM == 1 { print "processing " $0 " now"}
If you plan to do multi-level exploded of sections within sections, then "perl" might be a better tool for parsing and processing the file.
my 2 cents
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 07:11 AM
12-14-2005 07:11 AM
Re: Awk and rss feeds: awk question:
You can redirect in 'awk'. Remember to close files not in use as is always good practice. For example:
# awk '{print $0 >> "/tmp/output"};END{close "/tmp/output"}' /etc/hosts
...would copy '/etc/hosts' to '/tmp/output'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 10:54 AM
12-14-2005 10:54 AM
Re: Awk and rss feeds: awk question:
Rodney, that would be somewhat similar to:
awk '/
For every occurence of
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 12:31 PM
12-14-2005 12:31 PM
SolutionUsing your posted data, Rod's suggestion and mine, see if something like the following gives you what you want:
#!/usr/bin/awk -f
/^
/^<\/item>/{ITEM=0;close "tmp/out"n};
{if (ITEM == 1) {
print "processing " $0 " in section=" n > "/tmp/out"n
}}
...your output will appear (in this case) in three files, named "/tmp/out1", "/tmp/out2" and "/tmp/out3".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2005 06:15 AM
12-15-2005 06:15 AM
Re: Awk and rss feeds: awk question:
Hope this might help:
cat in.file | awk '/^
getline;
i++;
while ( $0 !~ "^<\/item>" ) {
print $0 >> "out." i
getline;
}
close "out." i
}'
Incase 'i' doesn't start from '1', use this:
cat in.file | awk 'begin{i=0}/^
getline;
i++;
while ( $0 !~ "^<\/item>" ) {
print $0 >> "out." i
getline;
}
close "out." i
}'