- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Parsing a single file into multiple files
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
Discussions
Discussions
Forums
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
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-28-2006 07:02 AM
тАО12-28-2006 07:02 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2006 07:08 AM
тАО12-28-2006 07:08 AM
Re: Parsing a single file into multiple files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2006 07:24 AM
тАО12-28-2006 07:24 AM
Re: Parsing a single file into multiple files
If you view the contents, it's a simple format. I just want to break it up into patch lists for each individual OS. Thanks.
- Tags:
- missing attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2006 07:31 AM
тАО12-28-2006 07:31 AM
SolutionIndeed, why not use 'csplit'. Given this file:
# cat ./patches
s700 10.10
PHCO_123
PHCO_456
s700 10.20
PHNE_12345
PHNE_22222
s800 11.0
PHKL_18543
PHSS_1234
PHSS_2222
...Using:
# csplit -s -f patchesfor ./patches '/s700 10.10/' '/s700 10.20/' '/s800 11.0/'
...produces files named "patchesfor00", "patchesfor01", "patchesfor02" and "patchesfor03". The first file is empty since there is nothing preceeding the first regular expression argument in the input file.
Regards!
...JRF...
- Tags:
- csplit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2006 08:04 AM
тАО12-28-2006 08:04 AM
Re: Parsing a single file into multiple files
# awk '{print $0 >> "patch."$3}' file
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-28-2006 11:39 AM
тАО12-28-2006 11:39 AM
Re: Parsing a single file into multiple files
It seems that a generalized 'csplit' something like:
# csplit -s -f patchesfor patches.txt '/^s/' '/^$/' '{35}'
...which should create files named 'patchesfor00'... dividing them into groups that begin with "s" [for s700 or s800] and ending with a blank line as the file you provide has, should work.
*However*, on my servers, I get an "{35} - out of range" error. You have thirty-one (31) files to generate given your data.
Sandman's suggestion is elegant (as his 'awk' always is!), but with your data, it doesn't behave as well as it should.
For example, within your stanza for s800 11.23 you have variously "11.23" and "11.X". I would think that you would still like to keep these grouped within the same output file.
*Hence*, I'd deploy a Perl solution like this:
# cat ./filter
#!/usr/bin/perl
use strict;
use warnings;
my $fh;
while (<>) {
if (/^s/) {
my @f = split( /[:\s]/, $_ );
my $file = "$f[0]_$f[1]";
open( $fh, ">>", $file ) or die "Can't open $file: $!\n";
}
print $fh $_;
}
1;
...Run as:
# ./filter patches.txt
Your output files will be produced in the directory in which you run this script. The files will be named like "s700_20.20", "s800_11.23", etc. based upon the first two fields (s700 or s800 and the release ID following it).
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 01:44 AM
тАО12-29-2006 01:44 AM
Re: Parsing a single file into multiple files
FILE=/dev/null
while read LINE; do
if [ -z "${LINE}" ]; then continue; fi
if [ -z "${LINE##s*}" ]; then
FILE=`echo $LINE|tr -s " " "_"`
else
echo $LINE >> $FILE
fi
done
Blank lines will be stripped.
Filenames will be as in JRF post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 01:49 AM
тАО12-29-2006 01:49 AM
Re: Parsing a single file into multiple files
By the way, would you please evaluate the responses you received in an earlier post, too. Thanks!
https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1063457
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 02:08 AM
тАО12-29-2006 02:08 AM
Re: Parsing a single file into multiple files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 02:51 AM
тАО12-29-2006 02:51 AM
Re: Parsing a single file into multiple files
BTW, if anyone hasn't rx'd points, let me know. I believe all w/script suggestions ahve been assigned. Thanks again.