awk printing question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk printing question
# 1  
Old 10-01-2012
awk printing question

im using awk as a part of my tasks to filter out stuff for reporting details in our storage environment, supposed i filtered out these details (sorry, this might be long.)


Code:
bash$ > for x in 1 2; do symdg show floras0-snap$x | awk  '{print $3,$4}'; done


: REGULAR
in GNS
Yes
: 000210107xxxx
Time :
: EMC
: SYMCLI

STD Devices
Associated GK's
Locally-associated BCV's
Locally-associated VDEV's
Locally-associated TGT's
Remotely-associated VDEV's(STD
Remotely-associated BCV's
Remotely-associated TGT's(TGT
Remotely-associated BCV's
Remotely-assoc'd RBCV's
Remotely-assoc'd BCV's
Remotely-assoc'd VDEV's(Hop-2
Remotely-assoc'd TGT's
Composite Groups
Names :

Devices (16):


Cap
Dev Config

2DB3 RAID-5
2DB4 RAID-5
2DB5 RAID-5
2DB6 RAID-5
02ED RAID-5
0E86 RAID-5
2DB7 RAID-5
2DB8 RAID-5
0E87 RAID-5
2DB9 RAID-5
2DBB RAID-5
2127 2-Way
2128 2-Way
10AE RAID-5
03C1 RAID-5
34BD RAID-5


Locally-associated (16):


Cap
Dev Config

1240 VDEV
1249 VDEV
124A VDEV
124B VDEV
124F VDEV
043A VDEV
124C VDEV
124D VDEV
043B VDEV
1250 VDEV
124E VDEV
2401 VDEV
2402 VDEV
1C83 VDEV
18DA VDEV
1331 VDEV



floras0-snap2

: REGULAR
in GNS
Yes
: 000190104699
Time :
: EMC
: SYMCLI

STD Devices
Associated GK's
Locally-associated BCV's
Locally-associated VDEV's
Locally-associated TGT's
Remotely-associated VDEV's(STD
Remotely-associated BCV's
Remotely-associated TGT's(TGT
Remotely-associated BCV's
Remotely-assoc'd RBCV's
Remotely-assoc'd BCV's
Remotely-assoc'd VDEV's(Hop-2
Remotely-assoc'd TGT's
Composite Groups
Names :

Devices (16):


Cap
Dev Config

2DB3 RAID-5
2DB4 RAID-5
2DB5 RAID-5
2DB6 RAID-5
02ED RAID-5
0E86 RAID-5
2DB7 RAID-5
2DB8 RAID-5
0E87 RAID-5
2DB9 RAID-5
2DBB RAID-5
2127 2-Way
2128 2-Way
10AE RAID-5
03C1 RAID-5
34BD RAID-5


Locally-associated (16):


Cap
Dev Config

0952 VDEV
0953 VDEV
0954 VDEV
0955 VDEV
0956 VDEV
0957 VDEV
0958 VDEV
0959 VDEV
095A VDEV
095B VDEV
095C VDEV
1908 VDEV
1909 VDEV
1243 VDEV
190C VDEV
095D VDEV


from this output, how can i filter the VDEVS only and print them side by side, then commit the VDEVS as shown in my desired output below ( these are the output from two device groups as i tried to loop using for.) please help, thanks.

desired output:

Code:
1240    0952
1249    0953
124A   0954
124B   0955
124F   0956
043A  0957
124C   0958
124D   0959
043B   095A  
1250   095B  
124E    095C  
2401   1908
2402   1909
1C83  1243
18DA 190C  
1331   095D


Last edited by Scrutinizer; 10-01-2012 at 04:00 AM.. Reason: code tags
# 2  
Old 10-01-2012
try this..

Code:
awk '{if($0 ~ /Dev Config/){a=1}else if($0 ~ /VDEV/){if(! X[a]){X[a]=$1;a++;if(a > max){max=a}}else{X[a]=X[a]" "$1;a++}}}END{
> for(i=1;i<max;i++){print X[i]}}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 10-01-2012
With some assumptions, try this:
Code:
awk 'FNR==NR{if($4=="VDEV") a[++i]=$3;next}
$4=="VDEV"{print a[++j],$3}' <(symdg show floras0-snap1) <(symdg show floras0-snap2)

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 10-01-2012
Code:
 
for x in 1 2; do symdg show floras0-snap$x | awk  '{print $3,$4}'; done > input.txt
awk '/floras0/{fname="snap"substr($0,length,1)}/VDEV$/{print $1 >fname}' input.txt
paste snap*

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 10-02-2012
thanks for the help but the outputs are in one straight column, the closest one i need is Pamu's solution but this is the output, how can i exclude the words?

Remotely-associated 1240 0952
Remotely-assoc'd 1249 0953
124A 0954
124B 0955
124F 0956
043A 0957
124C 0958
124D 0959
043B 095A
1250 095B
124E 095C
2401 1908
2402 1909
1C83 1243
18DA 190C
1331 095D
Locally-associated
Remotely-associated
Remotely-assoc'd

---------- Post updated at 11:45 AM ---------- Previous update was at 11:31 AM ----------

i got to delete them using grep -v but is quite long, is there a shorter approach to how i grep'd below?

awk '{if($0 ~ /Dev Config/){a=1}else if($0 ~ /VDEV/){if(! X[a]){X[a]=$1;a++;if(a > max){max=a}}else{X[a]=X[a]" "$1;a++}}}END{
for(i=1;i<max;i++){print X[i]}}' input.txt | grep -v 'Remotely-associated' | grep -v 'Locally-associated' | grep -v "Remotely-assoc'd"

output:
124A 0954
124B 0955
124F 0956
043A 0957
124C 0958
124D 0959
043B 095A
1250 095B
124E 095C
2401 1908
2402 1909
1C83 1243
18DA 190C
1331 095D

Last edited by prodigy06; 10-02-2012 at 12:35 AM.. Reason: - found out "thanks" link :)
# 6  
Old 10-02-2012
better way try this...

Code:
awk '{if($0 ~ /Dev Config/){a=1}else if($0 ~ /VDEV/ && $1 ~ /^[0-9]/){if(! X[a]){X[a]=$1;a++;if(a > max){max=a}}else{X[a]=X[a]" "$1;a++}}}END{  for(i=1;i<max;i++){print X[i]}}' file


Last edited by pamu; 10-02-2012 at 01:24 AM.. Reason: correction...
# 7  
Old 10-02-2012
i got this Pamu

awk '{if($0 ~ /Dev Config/){a=1}else if($0 ~ /VDEV/ && $1 ~ /^[0-9]/){if(! X[a]){X[a]=$1;a++;if(a > max){max=a}}else{X[a]=X[a]" "$1;a++}}}END{ > for(i=1;i<max;i++){print X[i]}}' input.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: bailing out near line 1
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk question for printing variables

Hi All, I have the following awk code where I am passing 4 variables to the program and I need to print them in the awk script. The variables are $start_month $start_date - $end_month $end_date. printf("\tFor More Information\n") > out_tmp1 printf("\tIf you have any questions about this... (6 Replies)
Discussion started by: nua7
6 Replies

2. Shell Programming and Scripting

Printing using awk

Hi I am relatively new to awk so i am getting confused a lot I am in need of help ... I am trying to append coloumns to the end of line using AWK I tried using this command awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 Replies

3. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

4. Programming

A question about printing error message with perror

Dear all, I use perror in order to print an error message to the standar error. For example if a C program is called without its two necessary command line parameters then : if (argc != 3) { perror("use: ./myProgram <source file> <target file>\n"); return 1; } Now the... (2 Replies)
Discussion started by: dariyoosh
2 Replies

5. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

6. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in quotes.like "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

7. UNIX for Dummies Questions & Answers

Silly question on printing for loop in AWK

Hi, One silly question. I would like to add statement like below and append to a file. I used the below code; however, it does not work. Can anyone please tell me what mistakes I have made? awk ' { for (i=1;i<=563;i++) print i }'>>output.txt Thanks. -Jason (1 Reply)
Discussion started by: ahjiefreak
1 Replies

8. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies

9. AIX

Stupid printing question

I am in the process of migrating software from HP-UX to AIX 5. On the HP box, instead of printing directly to the printer, we piped everything through a ksh script to set the printing parameters (such as landscape/portrait, 12.5 cpi, duplex, etc, etc) via the "-o" option. Since we move printers... (0 Replies)
Discussion started by: Highness
0 Replies

10. UNIX for Dummies Questions & Answers

question about printing number of lines in a file

as the title, I had try use "wc -l test.txt" but it give me "<many spaces> 384 test.txt" but the result I want is just "384" could any person can help me that? Thx:( (5 Replies)
Discussion started by: a8111978
5 Replies
Login or Register to Ask a Question