- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need the help with awk or Perl again.
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
03-12-2004 03:03 AM
03-12-2004 03:03 AM
DUKE|150791|0|0|150791|0
A pipe delimited file. The number of values in each line will always be the same
value of org_code, AFC
count of y MOL 125568
count of r MOL 3621
count of b MOL 10788
count of y KAU 125568
count of r KAU 3621
count of b KAU 10788
value of org_code, DUKE
count of y MOL 150791
count of r MOL 0
count of b MOL 0
count of y KAU 150791
count of r KAU 0
count of b KAU 0
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:23 AM
03-12-2004 03:23 AM
Re: Need the help with awk or Perl again.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:23 AM
03-12-2004 03:23 AM
Re: Need the help with awk or Perl again.
cat file | awk '
/value of/ {printf("%s",NF);}
/count of b/ {
count++;
printf("%s",NF);
if (count == 2 ) {
printf("\n");
count = 0;
next
}
/count of/ {printf("%s",NF);}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:26 AM
03-12-2004 03:26 AM
Re: Need the help with awk or Perl again.
#!/usr/bin/perl
open FILE,"datafile";
while($line=
chomp($line);
next if $line eq "";
($DATA)=($line=~/.+\b(.+)/);
if($line =~ /value of org_code/){
print "\n";
} else {
print "|";
}
print $DATA;
}
print "\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:27 AM
03-12-2004 03:27 AM
Re: Need the help with awk or Perl again.
cat file | awk '
/value of/ {printf("%s|",NF);}
/count of b/ {
count++;
if ( count == 2 ) {
printf("%s\n",NF);
count = 0;
}else {
printf("%s|",NF);
}
next;}
/count of/ {printf("%s|",NF);}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:46 AM
03-12-2004 03:46 AM
Re: Need the help with awk or Perl again.
#!/usr/bin/perl
open FILE,"datafile";
while(
next if $_ eq "";
($DATA)=($_=~/.+\b(.+)/);
if(/value of org_code/){
print "\n";
} else {
print "|";
}
print $DATA;
}
print "\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:49 AM
03-12-2004 03:49 AM
Re: Need the help with awk or Perl again.
AFC| | | | | |
DUKE| | | | | |
I get the ORg but no data in between the pipes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 03:54 AM
03-12-2004 03:54 AM
Re: Need the help with awk or Perl again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:05 AM
03-12-2004 04:05 AM
Solution- ignore if empty
- make seperator newline if more than 5 fields, bar if not.
- print last field and seperator.
awk '/^val/{x=0};(NF) {n=(x++>5)? "\n":"|"; printf "%s%s", $NF,n;}' < yourfile
In perl with a little more robust parsing:
- start fresh line if line begins with 'val'
- add seperator bar and field to line if line begins with count
- print line if more than 5 counts seen.
perl -ne 'if (/^val.*,\s+(\w+)$/){$l=$1; $nf=0}; if (/^cou.*\s(\w+)$/){$l.="|$1"; print "$l\n" if (++$nf>5)}' < yourfile
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:22 AM
03-12-2004 04:22 AM
Re: Need the help with awk or Perl again.
open F, "input" or die "$!";
while (
print "\n" && next if ($_ eq "");
@data = split/\s+/;
if (/^value/) {
print "$data[3]|";
}else{
print "$data[4]|";
}
}
this should do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:29 AM
03-12-2004 04:29 AM
Re: Need the help with awk or Perl again.
here ya go.
#!/usr/bin/perl
open F, "input" or die "$!";
while (
if (/^$/) { print "\n"; next; }
@data = split/\s+/;
if (/^value/) {
print "$data[3]|";
}else{
print "$data[4]|";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:35 AM
03-12-2004 04:35 AM
Re: Need the help with awk or Perl again.
awk -f useme.awk < datafile
Put the following in useme.awk:
BEGIN {linecnt=0;}
NF<4{next;}
/^value /{if (linecnt!=0)
{print daline;};
daline=$4;linecnt++;next;}
/^count/{daline=daline"|"$5;next}
END{print daline;}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 04:42 AM
03-12-2004 04:42 AM
Re: Need the help with awk or Perl again.
#!/bin/sh
awk '
{
if(substr($0,1,17)=="value of org_code") {
split($0,tab,",");
printf("%s",tab[2]);
for(i=1; i < 6;i++) {
getline;
printf("|%d",$5);
}
printf("\n");
}
}'
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 05:51 AM
03-12-2004 05:51 AM
Re: Need the help with awk or Perl again.
Curt both of your awk scripts gives the good old bail error at the end.
Could you give the error that your receiving?
I'd be glad to help you find the error.
I was able to run this script without any problems. It does have two modificaitons, $NF and next in the action of /value of/, but other then that it is the same as before.
cat file | awk '
/value of/ {printf("%s|",$NF);next;}
/count of b/ {
count++;
if ( count == 2 ) {
printf("%s\n",$NF);
count = 0;
}else {
printf("%s|",$NF);
}
next;}
/count of/ {printf("%s|",$NF);}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 05:58 AM
03-12-2004 05:58 AM
Re: Need the help with awk or Perl again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 06:09 AM
03-12-2004 06:09 AM
Re: Need the help with awk or Perl again.
here is an easy commandline version.
#perl -nae 'if(/^$/){print "\n";next;}if(/^value/){print "$F[3]";}else{print "|$F[4]"}' input_file
and a corrected version of my above posts.
open F, "input" or die "$!";
while (
if (/^$/) { print "\n"; next; }
@data = split/\s+/;
if (/^value/) {
print "$data[3]";
}else{
print "|$data[4]";
}
}
close F;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 06:22 AM
03-12-2004 06:22 AM
Re: Need the help with awk or Perl again.
AFC|125568|3621|10788|125568|3621|10788DUKE|150791|0|0|150791|0|0EXR|26009|8|322|889WRN|80759|422|3129|80759|422|3129YALE|144122|8|272|144122|8|272
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 06:52 AM
03-12-2004 06:52 AM
Re: Need the help with awk or Perl again.
I know the first one I posted did only do one line of output. But the last two should work.
# perl -nae 'if(/^$/){print "\n";next;}if(/^value/){print "$F[3]";}else{print "|$F[4]"}' input
AFC|125568|3621|10788|125568|3621|10788
DUKE|150791|0|0|150791|0|0
using perl 561
I attached my script and with it the command line commmented inside it.
Hopefully its useful for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 07:15 AM
03-12-2004 07:15 AM
Re: Need the help with awk or Perl again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2004 07:22 AM
03-12-2004 07:22 AM
Re: Need the help with awk or Perl again.
if that is not the case all the time. then it will do one continuous line of output.
As that blank line is what determines the newline.
the code is easy enough to change if that blank line is not always present.
if you need it modified so that blank line isn't required, It can be easily changed.