- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Pattern Search Fixed width Position
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
тАО02-25-2004 05:45 AM
тАО02-25-2004 05:45 AM
Pattern Search Fixed width Position
112223333sugar458696963
125632233water4589sugar
125632233people63336666
Output would be something like this
Output:
File 1
-------
112223333sugar4586969633
File 2
-------
125632233water45869sugar
125632233people633366666
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2004 06:29 AM
тАО02-25-2004 06:29 AM
Re: Pattern Search Fixed width Position
# grep "^\([0-9]\{9\}\)sugar\(.*$\)" testfile1 > outfile1
# grep -v -f outfile1 testfile1
125632233water4589sugar
125632233people63336666
# grep -v -f outfile1 testfile1 > outfile2
# cat outfile1
112223333sugar458696963
# cat outfile2
125632233water4589sugar
125632233people63336666
# cat testfile1
112223333sugar458696963
125632233water4589sugar
125632233people63336666
# grep "^\([0-9]\{9\}\)sugar\(.*$\)" testfile1 > outfile1
# grep -v -f outfile1 testfile1 > outfile2
# cat outfile1
112223333sugar458696963
# cat outfile2
125632233water4589sugar
125632233people63336666
#
Because it requires TWO passes and a LOT of OVERHEAD, I suggest you write a perl script to do it.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2004 06:35 AM
тАО02-25-2004 06:35 AM
Re: Pattern Search Fixed width Position
#
open(ORIGfileptr,"< ORIGFILE");
open(OUToneFileptr,"> file1");
open(OUTtwoFileptr,"> file2");
while (
if ( m/^([0-9]{9})sugar(.*$)/ ) {
printf OUToneFileptr $_;
} else {
printf OUTtwoFileptr $_;
}
}
close(ORIGfileptr);
close(OUToneFileptr);
close(OUTtwoFileptr);
change ORIGFILE (on the open line (the one in quotes)) to the real file name.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2004 06:53 AM
тАО02-25-2004 06:53 AM
Re: Pattern Search Fixed width Position
* What is the criterion to put a line in file 1 or file 2? The first number (9 digits)?
* Only 2 output files?
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2004 07:09 AM
тАО02-25-2004 07:09 AM
Re: Pattern Search Fixed width Position
However I was looking for an slightly different answer; to be precise, Pattern "Sugar" could be anything (non empty characters);
So basically the comparison would be something like this For instance(from position 10-14 non-empty characters spooled to 1 file and rest empty characters spooled to 2 file )
112223333sugar458696963
125632233water4589sugar
125632233people63336666
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2004 07:17 AM
тАО02-25-2004 07:17 AM
Re: Pattern Search Fixed width Position
#
open(ORIGfileptr,"< ORIGFILE");
open(OUToneFileptr,"> file1");
open(OUTtwoFileptr,"> file2");
while (
if ( m/^([0-9]{9})([A-Za-z]{5})(.*$)/ ) {
printf OUToneFileptr $_;
} else {
printf OUTtwoFileptr $_;
}
}
close(ORIGfileptr);
close(OUToneFileptr);
close(OUTtwoFileptr);
The change says that any ALPHA string five characters long in positions 10-14, go to "file1", all others go to "file2".
TO SHOW SPACES in your examples, use the "+" sign.
live free or die
harry