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
тАО03-05-2003 10:14 AM
тАО03-05-2003 10:14 AM
awk help
Is there a way that I can print $2 $4 $6 ...etc
if field $2 is -eq 2 && $6 = 6 then print $2 $4 $8.
eg
cat file | awk {if($2~/[2,3,5]1){print $0}} , will result in
BIL=84 3500 0c0000 31 49 1172850950 P=64 03030500251a 40 201c00 P=65 07 28505000 P=6e 06 4a54d53d P
=67 110000 P=7a 0100 P=6c 5244474c4142 0600 1b
BIL=84 3f00 0c0000 31 49 1148940550 P=64 03030500252e 40 201c00 P=65 0a 0124839026 P=8e 05 030000 P=6
e 06 6e39412a P=67 6f0000 P=7a 0200 P=6c 4a474d484142 0800 07 P=66 04 00 00
BIL=84 3f00 0c0000 31 49 1148940030 P=64 030305002536 40 201c00 P=65 0a 0124839028 P=8e 05 030000 P=6
e 06 8a64a712 P=67 6e0000 P=7a 0200 P=6c 4a4446484142 2f00 1c P=66 04 00 00
BIL=84 3b00 0c0000 51 49 1148307170 P=64 030305002609 40 160d00 P=65 0a 0860007249 P=82 05 1000 00 P=
6e 06 4ad2db3d P=67 080000 P=7a 0100 P=6c 4842574c4142 0900 1d
What I want to achieve is to print only the fields that I request for eg
1172850950 03030500251a 28505000 201c00 4a54d53d
1148940550 03030500252e 0124839026 201c00 6e39412a
???etc
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 10:21 AM
тАО03-05-2003 10:21 AM
Re: awk help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 10:33 AM
тАО03-05-2003 10:33 AM
Re: awk help
awk use $2 too to field #2 and $6 to field #6
so you like to something like:
awk ' $2 == sh_var2 && $6 == sh_var6 { print $2 $4 $8 }' sh_var2=$2 sh_var6=$6 file
??????
Put a example of your file, values for search and output expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 10:33 AM
тАО03-05-2003 10:33 AM
Re: awk help
Thanks. If you look at the file after I printed it you will see that "1172850950" is $6
and 03030500251a is $8, 28505000 is $13,"201c00" is $10 and this is were my problem lays is the next $variable. It is sometimes at $16, $19 and $20 ..etc, (common is "P=6e")
Thanks Once again
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 10:49 AM
тАО03-05-2003 10:49 AM
Re: awk help
Maybe you need to use NF variable or/and for
awk '{ print NF , $NF , $(NF-3) }' file
will print #fields last field (last_field)-3
you can write something like
{ for ( f=20; f
( if == "P=6e" ) print $(f+1)
}
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 11:04 AM
тАО03-05-2003 11:04 AM
Re: awk help
My Output file looks like this :
BIL=84 3500 0c0000 31 49 1172850950 P=64 03030500251a 40 201c00 P=65 07 28505000 P=6e 06 4a54d53d P=67 110000 P=7a 0100 P=6c 5244474c4142 0600 1b
BIL=84 3f00 0c0000 31 49 1148940550 P=64 03030500252e 40 201c00 P=65 0a 0124839026 P=8e 05 030000 P=6e 06 6e39412a P=67 6f0000 P=7a 0200 P=6c 4a474d484142 0800 07 P=66 04 00 00
...
...
From the above example, my Output must look like this:
1172850950 03030500251a 28505000 201c00 4a54d53d
1148940550 03030500252e 0124839026 201c00 6e39412a
Hope this is of help
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 11:21 AM
тАО03-05-2003 11:21 AM
Re: awk help
BIL= $8 ... P=64 print_this ... P=6e print_this_also ...
So from each line starting with "BIL=" you want to print field #8 and the field following the token "P=64" and the field following the token "P=6e"
And you can not predict, if in the ... spaces are zero or more other tokens in between ?
Is the sequence of P=64 and P=6e predictable, or can P=6e be switched with P=64 ?
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 11:48 AM
тАО03-05-2003 11:48 AM
Re: awk help
Yes the record starts at BIL=84 and yes I want to print #6 ,#8 ,#13, #10 , which are aligned which is no problem, but when it comes to "P=6e" ,it is sometimes at #16 or #19 or #20 depending on the bytes before P=6e
for example
BIL=84 .. .. .. .. . P=65 0a 0124839028 P=8e 05 030000 P=6e 06 8a64a712 ( <---this is #19)
BIL=84 .. ... ... .. P=65 0a 0860007249 P=82 05 1000 00 P=6e 06 4ad2db3d (<---this is #20)
and
BIL=84 .. .. .. .. . P=64 03030500251a 40 201c00 P=65 07 28505000 P=6e 06 4a54d53d (<---this is #16)
Does this help
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 02:20 PM
тАО03-05-2003 02:20 PM
Re: awk help
perl -n -e 'chomp; /^BIL=(\S+\s+){5,5}(\S+)/ && do {$a1=$2};/P=64 (\S+)\s+\S+\s+(\S+)/ && do {$a2=$1;$a4=$2};/P=65 \S+\s+(\S+)/ && d
o {$a3=$1};/P=6e \S+\s+(\S+)/ && do {$a5=$1};print join(" ",$a1,$a2,$a3,$a4,$a5),"\n";' yourfile
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2003 03:21 PM
тАО03-05-2003 03:21 PM
Re: awk help
A combination of shell and awk. This will print the output in the format you wanted, except for the 10th and 13th field. Once the output is generated, you can easily use another simpl e awk statement to put them in order. Modify the DATA variable with your file
//
#!/usr/bin/ksh
DATA=data
grep "^BIL" $DATA |while read line
do
echo $line |awk '
{
if ( $0 ~ "^BIL" )
{
for (e=1; e <= NF; e++)
{
if ( $e ~ "P\=6e" ) {
printf ("%s ", $(e+2))
exit }
else
{
if ( e == 6 || e == 8 || e == 10 || e == 13 ) {
printf ("%s ", $e)}
}
}
}
}'
printf "\n"
done
//
-Sri