- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Header and Trailer Records..Continues
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
04-05-2006 05:10 AM
04-05-2006 05:10 AM
Header and Trailer Records..Continues
sed -e '1'd -e '$'d file1 > file2 works fine for me. i.e it removes header and trailer records. however .. i want to make sure
i'm removing only header and trailer records and not actual data (if there is no header/trlr record in it)... i can distingush header / trlr record by following..
header records will be something like this
HDR*#20060327
and trailer will be
TRLR*#0002401372
so i need to check for this matching patterns ( HDR*# or TRLR*#) before i remove hdr/trlr records.if pattern doesnt match then it shudnt anything..
Sample Data
HDR*#20060327
CUST001 100 200 4500
CUST200 376 365 7889
CUST400 567 589 6869
TRLR*#0002401372
PLS HELP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 05:16 AM
04-05-2006 05:16 AM
Re: Header and Trailer Records..Continues
This is along the same lines as I suggested in your first post:
# perl -ne 'print unless m/^HDR\*#|^TRLR\*#/' filein
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 05:21 AM
04-05-2006 05:21 AM
Re: Header and Trailer Records..Continues
awk '{ if (!($0 ~ /^HDR/) && !($0 ~ /^TRLR/)) print $0 }' < infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 05:26 AM
04-05-2006 05:26 AM
Re: Header and Trailer Records..Continues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 06:28 AM
04-05-2006 06:28 AM
Re: Header and Trailer Records..Continues
Nope .. i dont need to store the HDR and TRLR records in different file..i just need to ignore them... and my input file going to be always in same format and thats
HDR*#20060327
CUST001 100 200 4500
CUST200 376 365 7889
CUST400 567 589 6869
TRLR*#0002401372
with first record (should) starts with HDR
and last records (should) start with TRLR..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 06:39 AM
04-05-2006 06:39 AM
Re: Header and Trailer Records..Continues
Either the Perl or awk will support your needs.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 06:47 AM
04-05-2006 06:47 AM
Re: Header and Trailer Records..Continues
****************8
#!/usr/bin/awk -f
date
echo "IN"
awk '{ if (!($0 ~ /^HDR/) && !($0 ~ /^TRLR/)) print $0 }' < mycust.dat > mycust_output.dat
echo "OUT"
date
******************
I get the following error
awk: syntax error near line 1
awk: illegal statement near line 1
I'm totally new to awk (and unix).. can you please let me know how to debug?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 06:49 AM
04-05-2006 06:49 AM
Re: Header and Trailer Records..Continues
# awk '!/^HDR\*\#/&&!/^TRLR\*\#/' inp
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 06:54 AM
04-05-2006 06:54 AM
Re: Header and Trailer Records..Continues
The error is with line below...
>>#!/usr/bin/awk -f<<
...since the shell expects awk commands instead of shell commands etc.
Change the above line to...
#!/usr/bin/sh
...and it should work for you.
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 07:01 AM
04-05-2006 07:01 AM
Re: Header and Trailer Records..Continues
#!/usr/bin/awk -f
Remove it completely or change it to:
#!/usr/bin/sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 07:13 AM
04-05-2006 07:13 AM
Re: Header and Trailer Records..Continues
#!/usr/bin/ksh
I got the following error
awk: syntax error near line 1
awk: illegal statement near line 1
and i saw #!/usr/bin/awk in someother program and thought in order for awk to work may be i need to include this ...but didnt work ..
Now i changed again to
#!/usr/bin/ksh and tried ..getting same error
#!/usr/bin/sh and tried ... getting same error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 07:16 AM
04-05-2006 07:16 AM
Re: Header and Trailer Records..Continues
I suggest you also evaluate:
# perl -ne 'print unless m/^HDR\*#|^TRLR\*#/' filein > fileout
...OR: if you prefer to update inplace (while creating an automatic backup file with an extension of ".old" corresponding to *your* input file name), do:
# perl -ni.old -e 'print unless m/^HDR\*#|^TRLR\*#/' filein
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 07:36 AM
04-05-2006 07:36 AM
Re: Header and Trailer Records..Continues
grep -v -e '^HDR' -e '^TRLR' filename > outfile
?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2006 07:37 AM
04-05-2006 07:37 AM
Re: Header and Trailer Records..Continues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 03:33 AM
04-07-2006 03:33 AM
Re: Header and Trailer Records..Continues
awk '{ if (!($0 ~ /^HDR/) && !($0 ~ /^TRLR/)) print $0 }' < mycust.dat > mycust_output.dat
This works ..but i'm getting a basic doubt now..fine ...but what that && does here ??
does it checks
line should not start with
[HDR AND TRLR ] or
[HDR OR TRLR]
i assume its [HDR AND TRLR ]
if thats the case how it removes
my first records when it has(starts with) only HDR in it ?
i get a feeling..i'm missing something basic.. Can some clarify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2006 03:40 AM
04-07-2006 03:40 AM
Re: Header and Trailer Records..Continues
Yes, the "&&" is a logical AND and "!" is a negation, so the code reads "...if NOT a header AND NOT a trailer, then print".
The Perl code I suggested works analogously, saying "...print unless a header OR a trailer". Of course, Perl's syntax differs from 'awk'.
Regards!
...JRF...
Regards!
...JRF...