- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script help
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-20-2010 05:44 AM
12-20-2010 05:44 AM
i have to manipulate many files which rows (cat -vn) always change.But what i have to do;
1 -All these files start (first records start with 811)
2- it is like an array when starts with 811*
then must end with an another record 819*
so this means this is a meaningfull record THEN I have to produce a random file from the original file...Here is an example;
My original_file records like;
811020000060810000056970000100001101213 DE811125281
8120201202504101213000000000000000000001716909789501202504000 0000000171690
8130105077820101213 00 B80037 00000000000000000000000000 000104275
8140381.06225-6007 81062256007 00000000970009900000000017700000000171690 004 0000Y000010 B80037
819030000001000000100000010000001000000100000001716900000000171690000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202511101213000000000000000000001807509789501202511000 0000000180750
8130105077819101213 00 B80037 00000000000000000000000000 000090000
8140381.15205-5307 81152055307 00000000150009900000000120500000000180750 004 0000Y000010 B80037
819030000001000000100000010000001000000100000001807500000000180750000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202506101213000000000000000000004044309789501202506000 0000000404430
8130105077815101213 00 B80037 00000000000000000000000000 000178500
8140381.46730-6097 81467306097 00000000170009900000000237900000000404430 004 0000Y000010 B80037
819030000001000000100000010000001000000100000004044300000000404430000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202505101213000000000000000000000019909789501202505000 0000000001990
8130105077821101213 00 B80037 00000000000000000000000000 000000725
8140382.97485-0825 82974850825 00000000050009900000000003980000000001990 AT 0000Y000010 B80037
819030000001000000100000010000001000000100000000019900000000001990000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202514101213000000000000000000000024549789501202514000 0000000002454
8130105078047101213 00 B80037 00000000000000000000000000 000000120
8140381.25503-6471 81255036471 00000000060009900000000004090000000002454 004 0000Y000010 B80037
819030000001000000100000010000001000000100000000024540000000002454000000000000000000000000000000000000000000000
SO I have to produced a file witha random filename and this file includes records from my orginal file but it smust be like;
811020000060810000056970000100001101213 DE811125281
8120201202504101213000000000000000000001716909789501202504000 0000000171690
8130105077820101213 00 B80037 00000000000000000000000000 000104275
8140381.06225-6007 81062256007 00000000970009900000000017700000000171690 004 0000Y000010 B80037
81903000000100000010000001000000100000010000000
Any suggestions would be appreciated...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 05:50 AM
12-20-2010 05:50 AM
Re: shell script help
811020000060810000056970000100001101213 DE811125281
8120201202506101213000000000000000000004044309789501202506000 0000000404430
8130105077815101213 00 B80037 00000000000000000000000000 000178500
8140381.46730-6097 81467306097 00000000170009900000000237900000000404430 004 0000Y000010 B80037
819030000001000000100000010000001000000100000004044300000000404430000000000000000000000000000000000000000000000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:05 AM
12-20-2010 06:05 AM
Re: shell script help
If what you want extracted is the groups of lines beginning with "811" and ending with "819" you could do:
# perl -ne '/^811/../^819/ and print' file
If you want only the first group matching this range, do:
# perl -ne '?^811?..?^819? and print' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:19 AM
12-20-2010 06:19 AM
Re: shell script help
Thank you...yes i want extracted is the groups of lines beginning with "811" and ending with "819" so this means I will produced may files from my orginal_file BUT
perl -ne '/^811/../^819/ my_orginal_file
not worked!!! Did I do anything wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:25 AM
12-20-2010 06:25 AM
Re: shell script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:37 AM
12-20-2010 06:37 AM
Re: shell script help
> yes i want extracted is the groups of lines beginning with "811" and ending with "819" so this means I will produced may files from my orginal_file BUT ...
Since you don't have anything other than successive ranges in your original input you could do:
# perl -ne 'if (?^811?..?^819?) {print};reset,print "\n" if /^819/' file
This would inject a blank line between the ranges. Is that your objective?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:46 AM
12-20-2010 06:46 AM
Re: shell script help
perl -ne 'if (?^811?..?^819?) {print};reset,print "\n" if /^819/' my_orignal_file
BUT this time i need i want to write out these records to new files.That's what i want.
From your command the output is seen;
811020000060810000056970000100001101213 DE811125281
8120201202504101213000000000000000000001716909789501202504000 0000000171690
8130105077820101213 00 B80037 00000000000000000000000000 000104275
8140381.06225-6007 81062256007 00000000970009900000000017700000000171690 004 0000Y000010 B80037
819030000001000000100000010000001000000100000001716900000000171690000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202511101213000000000000000000001807509789501202511000 0000000180750
8130105077819101213 00 B80037 00000000000000000000000000 000090000
8140381.15205-5307 81152055307 00000000150009900000000120500000000180750 004 0000Y000010 B80037
819030000001000000100000010000001000000100000001807500000000180750000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202506101213000000000000000000004044309789501202506000 0000000404430
8130105077815101213 00 B80037 00000000000000000000000000 000178500
8140381.46730-6097 81467306097 00000000170009900000000237900000000404430 004 0000Y000010 B80037
819030000001000000100000010000001000000100000004044300000000404430000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202505101213000000000000000000000019909789501202505000 0000000001990
8130105077821101213 00 B80037 00000000000000000000000000 000000725
8140382.97485-0825 82974850825 00000000050009900000000003980000000001990 AT 0000Y000010 B80037
819030000001000000100000010000001000000100000000019900000000001990000000000000000000000000000000000000000000000
811020000060810000056970000100001101213 DE811125281
8120201202514101213000000000000000000000024549789501202514000 0000000002454
8130105078047101213 00 B80037 00000000000000000000000000 000000120
8140381.25503-6471 81255036471 00000000060009900000000004090000000002454 004 0000Y000010 B80037
819030000001000000100000010000001000000100000000024540000000002454000000000000000000000000000000000000000000000
AND GOES ON...But i need that each [811-819] block has to be >> a new filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 06:53 AM
12-20-2010 06:53 AM
Re: shell script help
> But i need that each [811-819] block has to be >> a new filename
Oh, OK, that's easily done. Try this:
# cat ./rangedivide
#!/usr/bin/perl
use strict;
use warnings;
my ( $fh, $file, $nbr );
$file = "myoutput";
$nbr = 1;
while (<>) {
if (?^811?..?^819?) {
if (/^811/) {
open( $fh, '>', "$file.$nbr" ) or die;
}
print $fh $_;
}
if (/^819/) {
close $fh;
reset;
$nbr++;
}
}
1;
...run as :
# ./rangedivide file
As written, your output file(s) will be named "myoutput.n" where 'n' ranges from one to the number of ranges seen.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 07:12 AM
12-20-2010 07:12 AM
Re: shell script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 07:16 AM
12-20-2010 07:16 AM
Re: shell script help
That's what i want.
Thank you very much....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 07:19 AM
12-20-2010 07:19 AM
Solution> ./rangedivide.sh: 0403-057 Syntax error at line 1 : `(' is not expected.
Did you cut-and-paste what I posted? Also, don't name the script "*.sh". That infers a shell script as opposed to a Perl one. If you want to use a file extension, use '*.pl'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 07:23 AM
12-20-2010 07:23 AM
Re: shell script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 08:20 AM
12-20-2010 08:20 AM
Re: shell script help
No, it implies a shell script. _You_ might
infer that it's a shell script. (But what's
in the file matters more than the name in
this case.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2010 09:00 AM
12-20-2010 09:00 AM
Re: shell script help
@Steven: > [...] That infers a shell script [...]
No, it implies a shell script.
Well, there is the usage notes for the word 'infer' here:
http://dictionary.reference.com/browse/infer
But then this would buttress your suggested distinction :-)
http://www.wsu.edu/~brians/errors/imply.html
Regards!
...JRF...