Sponsored Content
Top Forums Shell Programming and Scripting Formatting grep and awk output Post 302827365 by ctsgnb on Friday 28th of June 2013 01:51:51 PM
Old 06-28-2013
Code:
awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x OFS $NF}$NF=="No"{print x;x=z}'  yourfile

Make sure it fits with your expectations, or feel free to adjust to your requirements.
What i get is like :

Code:
$ cat tst
="SEIDBABAK01",="SEIDBABAK01_212E4_VMAX2673_FA13e1",="10000000c93212e4",="SEI_FABRIC_1_BOTTOM",="Switch_9"

Symmetrix ID            : 000192602673

Director Identification : FA-13E
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 Yes    Yes

Director Identification : FA-8F
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93212e4 Fibre 10000000c93212e4 10000000c93212e4 618180 No     No

####################################################



BLANK,="POST07_HBA_1_VMAX2673_FA_5F1",="10000000c93d51d7",="SEI_FABRIC_2_TOP",="Switch_10"

Symmetrix ID            : 000192602673

Director Identification : FA-5E
Director Port           : 0

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     No

Director Identification : FA-5F
Director Port           : 1

                            User-generated                      Logged On
Identifier       Type  Node Name        Port Name        FCID   In     Fabric
---------------- ----- --------------------------------- ------ ------ ------
10000000c93d51d7 Fibre 10000000c93d51d7 10000000c93d51d7 680913 No     Yes

####################################################
$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x OFS $NF}$NF=="No"{print x;x=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-13E 1 FA-8F 0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E 0
$

Note that :
a) the code does not print to the last "No" before the #### but
until it meet the first "No"
b) you can also enforce the code by adding a cleanup condition of x variable like /####/{x=z}

Code:
$ awk -F"[, ]" '$0!~/./{next}/,/{gsub(/[="]*/,z);x=$2 OFS $3}/r Id|r Po/&&x{x=x (/r Po/?":":OFS) $NF}$NF=="No"{print x;x=z}' tst
SEIDBABAK01_212E4_VMAX2673_FA13e1 10000000c93212e4 FA-13E:1 FA-8F:0
POST07_HBA_1_VMAX2673_FA_5F1 10000000c93d51d7 FA-5E:0


Last edited by ctsgnb; 06-28-2013 at 03:27 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about formatting output using AWK

Hi everyone. I've got this fille... 0 5000001 5000002 5000003 5000006 5000007 5000219 11000156 11003130 11003132and this script... #!/bin/ksh FILE_ALERT_CONTACT_LIST=users.txt userID=`awk -F"=" '{printf $1 ", "}' $FILE_ALERT_CONTACT_LIST` (9 Replies)
Discussion started by: Fatbob
9 Replies

2. Shell Programming and Scripting

Output formatting of grep

hi, I am trying to find the word "root" from the follwoing sample file: #12.12.12.2222 echo "Hai........" 11.11.1.1111 3.23.AS.AA ab.cd.df.rf /usr/bin jhhh 12.12.AF.12 /urf/sss/kk kkk su sh.s exec su root; ,root sudo -sh cosrootex (3 Replies)
Discussion started by: flamingo_l
3 Replies

3. Shell Programming and Scripting

output formatting with awk.

# echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin How would i write a script to display permission on each folders in $PATH variable below format. drwxr-xr-x 2 0 root 4096 Nov 24 14:51 /usr/kerberos/sbin drwxr-xr-x 2 0... (2 Replies)
Discussion started by: pinga123
2 Replies

4. Shell Programming and Scripting

Formatting of output from awk

Hi; i m running an command like; getfacl $(find /home/fstl/testShell/ -type f -ls | awk '{print $11}') and i m getting outpiut for all files in "testShell" folder as; # file: home/fstl/testShell/.script1.sh.swp # owner: root # group: root user:fstl:rw- user:ajay:rw- group:root:r--... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

5. Shell Programming and Scripting

Formatting output using awk in ksh

:oi was trying to write a script to format output of a command in ksh which has output as below: so i used : to get which i require at all times. But problem occurs when status part changes. above output i get when status is SU (success).If the status is IN (inactive), output of... (1 Reply)
Discussion started by: pr5439
1 Replies

6. Shell Programming and Scripting

awk or grep to search one column and output the other

Hello, it would be great if someone can help me with the following: I want to search for the rows from fileA in column 1 of fileB and output column 2 of fileB if found in fileC. In the moment I search within the complete file. How can I change the code so only column 1 is searched? cat fileA... (7 Replies)
Discussion started by: Manyaka
7 Replies

7. Shell Programming and Scripting

awk - grep particular word from output

Hi Experts, - Getting error while using it through a variable to get the PID, PID=42 # UNIX95=1 ps -e -o pcpu,pid,ppid,stime,etime,args | awk '{if ($2~"^42$") print $0}' 0.00 42 0 Feb 10 600-17:21:29 nfs_async_io - But when using with a variable it is not working . #... (6 Replies)
Discussion started by: rveri
6 Replies

8. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

9. Shell Programming and Scripting

Grep output to awk command

Hi Team(Solaris 5.8/Ksh), How can we save grep output to awk variable when grep returns more than one line or word. abc.log # more abc.log Hi Makarand How r u bye Makarand Hello when grep returns only 1 word below command works nawk -v var=`cat abc.log |grep "Hello"` 'BEGIN { if... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

10. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies
All times are GMT -4. The time now is 01:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy