- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk / sed 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
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
тАО07-15-2009 10:20 AM
тАО07-15-2009 10:20 AM
I am needing some assistance with a shell script.
I have a master file that is pipe "|" delimited.
My goal is to search through the file looking specifically for a few fields and if they meet a condition I have to change one of the fields and save the file.
Here is what I am looking for:
If COL 165 is = to COMPANY PAID and COL 63 does not = AIRFARE - DIRECT BILLED then within that same line replace COL 165 COMPANY PAID with JPMC CORPORATE CARD and save file.
Same conditions for every line with specifics of above.
I would rather not use perl unless it is a last resort.
Many thanks (points will be awarded)
DCJ
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 10:49 AM
тАО07-15-2009 10:49 AM
Re: Awk / sed script help.
Posting an actual file (as an attachment) is far more helpful than a word description of columns and column contents.
If their are less than 199 fields in the file, 'awk' may suffice.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 11:02 AM
тАО07-15-2009 11:02 AM
SolutionBEGIN {
FS="|";
OFS="|";
}
{
if ($165 == "COMPANY PAID" && $63 != "AIRFARE - DIRECT BILLED")
{
$165 = "COMPANY PAID with JMPC CORPORATE CARD";
}
print $0;
}
END{
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 11:09 AM
тАО07-15-2009 11:09 AM
Re: Awk / sed script help.
OldSchool, thanks I will give this a try.
many thanks fellas.
DCJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 11:19 AM
тАО07-15-2009 11:19 AM
Re: Awk / sed script help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 11:39 AM
тАО07-15-2009 11:39 AM
Re: Awk / sed script help.
I forgot to even mention I was doing this on (cough cough) Solaris... :)
Your snippet led me down the what looks to be correct path.
Here is what my command looks like to do this:
cat TEST.txt | nawk 'BEGIN { FS="|"; OFS="|"; } { if ($165 == "COMPANY PAID" && $63 != "AIRFARE - DIRECT BILLED") { $165 = "JMPC CORPORATE CARD"; } print $0; } END{ }' > NEWTEST.txt
Just for my sanity do you all mind trying this to confirm?
Thanks abunch fellas I just needed a little guidance.
Thanks again
DCJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 11:49 AM
тАО07-15-2009 11:49 AM
Re: Awk / sed script help.
Based on your data, I see more than 199 fields too. The good old 'awk' is going to choke on that, but Perl never will.
Try this:
# cat ./reformat
#!/usr/bin/perl
use strict;
my @a;
while (<>) {
@a = split /\|/;
if ( $a[164] eq 'COMPANY PAID' && $a[62] ne 'AIRFARE - DIRECT BILLED' ) {
print join '|', @a[ 0 .. 163 ],
'COMPANY PAID with JMPC CORPORATE CARD', @a[ 165 .. $#a + 1 ];
}
else {
print;
}
}
1;
...run as:
# ./reformat file
Note that Perl counts zero-relative, so I adjusted the field counts accordingly.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 12:06 PM
тАО07-15-2009 12:06 PM
Re: Awk / sed script help.
well, it worked on AIX, changed 2 records in the test data provided.
but....
1) skip the "cat', its not needed...
nawk 'BEGIN { FS="|"; OFS="|"; } { if ($165 == "COMPANY PAID" && $63 != "AIRFARE - DIRECT BILLED") { $165 = "JMPC CORPORATE CARD"; } print $0; } END{ }' TEST.txt > NEWTEST.txt
will let nawk read / process the file itself....and
2) not sure why you'd want one long command line... to me, something like this:
cat cardchange.awk
BEGIN {
FS="|";
OFS="|";
}
{
if ($165 == "COMPANY PAID" && $63 != "AIRFARE - DIRECT BILLED")
{
$165 = "JMPC CORPORATE CARD";
}
print $0;
}
END{
}
used with:
nawk -f cardchange.awk TEST.txt > NEWTEST.txt
is just easier to maintain