1827882 Members
1625 Online
109969 Solutions
New Discussion

Korn Shell Script Help

 

Korn Shell Script Help

Hi,

Kindly assist me.

I have output as per attached.

I need to extract FROZEN ID.
My output format should be as follow :

ID Status
006707 FROZEN

Thanks
-Kamarul
7 REPLIES 7
Tim Nelson
Honored Contributor

Re: Korn Shell Script Help

awk 'NR > 5 {print $1 "FROZEN}' myfile.txt
Tim Nelson
Honored Contributor

Re: Korn Shell Script Help

sorry, forgot a quote
awk 'NR > 5 {print $1 "FROZEN"}' myfile.txt
Hein van den Heuvel
Honored Contributor

Re: Korn Shell Script Help

Sounds like simple text processing possibly best done in AWK or PERL, not in a shell loop.

Here is a possible solution:

$ cat x.pl
#!/usr/bin/perl
use strict;
use warnings;
my $id;
my $header=0;
#
# Read in all data lines from STDIN or first file mentioned.
#
while (<>) {
$id = $1 if /^(\d+)\s/; #Looks like an id? Remember it.
if (/FROZEN\s+$/) { # Line ends in 'FROZEN'?
print " ID Status\n" unless $header++;
print "$id FROZEN\n";
}
}
$ ./x.pl x
ID Status
006707 FROZEN

Enjoy,
Hein.
Sandman!
Honored Contributor

Re: Korn Shell Script Help

# awk 'BEGIN{print "Id\tStatus"} {if($0~"FROZEN") print l"\t"$NF;l=$1}' file
Dennis Handly
Acclaimed Contributor

Re: Korn Shell Script Help

>Tim: awk 'NR > 5 {print $1 "FROZEN"}'

The problem here is that the ID is on the first of a two line pair. Checking NR > 5 also fails because of the titles and the line with "FULL" and the first of the pair.

Sandman's solves those issues.

Re: Korn Shell Script Help

Thanks All,

Tim, I got the following output that not as expected.
cel8484_MHS:/home/sup01/FREEZE# awk 'NR > 5 {print $1 "FROZEN"}' media_freeze_v2.dat
005837FROZEN
17FROZEN
FROZEN
005842FROZEN
19FROZEN
FROZEN
006703FROZEN
15FROZEN
FROZEN
006704FROZEN
0FROZEN
FROZEN
006707FROZEN
6FROZEN
FROZEN
006710FROZEN
7FROZEN

Hein, great!! I got the output as I'm expected.
Thanks although I'm not familiar with perl but got the solution.

Sanman, also great. I got it & thanks.

Dennis, thanks for your reply.

Dennis Handly
Acclaimed Contributor

Re: Korn Shell Script Help

You haven't assigned any points here. If some of the answers were useful, thank us by points. That way everyone else knows which are useful.
See the following:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
You can reopen by:
http://forums1.itrc.hp.com/service/forums/helptips.do?#41