Read from text file;format and print output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from text file;format and print output
# 1  
Old 03-22-2013
Read from text file;format and print output

Hi Following is the assumed input...
Code:
Symmetrix ID        : 12345

Originator Port wwn : 123456789
User-generated Name : 123456789/123456789

Sym Dev  Dir:P                                            LUN
------  -----  -----------------------  ----  ---  ---- ----  ----  -------
1234     8A:1  Not Visible                 0    0    61  N/A  (M)     17261
5678     8C:1  Not Visible                 0    0    75  N/A  (M)     25892
9123     8C:1  Not Visible                 0    0    80  N/A  (M)    153563
4567     8A:1  Not Visible                 0    0    67  N/A          219
Symmetrix ID        : 12345

Originator Port wwn : 123456789
User-generated Name : 123456789/123456789

Sym Dev  Dir:P                                            LUN
------  -----  -----------------------  ----  ---  ---- ----  ----  -------
1234     8A:1  Not Visible                 0    0    61  N/A  (M)     17261
5678     8C:1  Not Visible                 0    0    75  N/A  (M)     25892

Symmetrix ID        : 12345

Originator Port wwn : 123456789
User-generated Name : 123456789/123456789

Sym Dev  Dir:P                                            LUN
------  -----  -----------------------  ----  ---  ---- ----  ----  -------
1234     8A:1  Not Visible                 0    0    61  N/A  (M)     17261
5678     8C:1  Not Visible                 0    0    75  N/A  (M)     25892
9123     8C:1  Not Visible                 0    0    80  N/A  (M)    153563


I need output as below:
Code:
Originator Port WWN        Sym Dev             Dir:P

123456789        1234,5678,9123,4567    8A:1,8C1,8A1,8C1
123456789        1234,5678        8A:1,8C1
123456789        1234,5678,9123        8A:1,8C1,8A1


Please help .tried using awk but dint help

Last edited by Franklin52; 03-22-2013 at 05:00 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 03-22-2013
Please explain how we are to determine when colons are to be dropped from entries in the 3rd column of the output, why the output order in the 3rd column doesn't match the output order of the 2nd column of output, and why some occurrences of 8C:1 seem to be randomly changed to 8A1. It would be fairly easy to produce:
Code:
123456789 1234,5678,9123,4567 8A:1,8C:1,8C:1,8A:1
123456789 1234,5678 8A:1,8C:1
123456789 1234,5678,9123 8A:1,8C:1,8C:1

but I can't see pattern that would produce the output you need.
# 3  
Old 03-22-2013
Hi Don,

Thanks for checking.
if below is input

Symmetrix ID : 12345

Originator Port wwn : 123456789
User-generated Name : 123456789/123456789

Sym Dev Dir:P LUN
------ ----- ----------------------- ---- --- ---- ---- ---- -------
1234 8A:1 Not Visible 0 0 61 N/A (M) 17261
5678 8C:1 Not Visible 0 0 75 N/A (M) 25892
9123 8C:1 Not Visible 0 0 80 N/A (M) 153563
4567 8A:1 Not Visible 0 0 67 N/A 219
....
...
..
Symmetrix ID : 12345

This will be the format in input file.. what I need is output should ahve Originator Port wwn : 123456789 and numbers under Sym dev and Dir:P columns and WWN in a table format...i.e.,

Originator Port wwn symdev dirSmilie
123456789 1234,5678,9123,4567,...,...,.. 8A:1,8C:1,8a:1,8c:1

---------- Post updated at 01:41 AM ---------- Previous update was at 01:26 AM ----------

wwn symdev dir.p
12345678 1234,5678,9123,4567 8a:1,8c:1

---------- Post updated at 01:49 AM ---------- Previous update was at 01:41 AM ----------

i am sorry., data is not formatting correctly with spaces..

here is what i need.. from input it should colelct wwn info, list under symdev, list under dir.p columns and print like below


wwn symdev dir.p
xxxx xx,yy,zz xx:x,yy:y

under dirSmilie xx:x ;yy:y ":'" is pattern how dir : p column is displayed..
# 4  
Old 03-22-2013
If you would use CODE tags as required in this forum it would help with your spacing issues. That wouldn't, however, do anything about inconsistent capitalization. I think this does what you want, even though the output produced doesn't match any of the output you specified:
Code:
awk '
function ps() {
        if(wwn) print wwn, sym, dir
        else    print "wwn symdev dir.p"
        dir = sym = wwn = ""
}
/^Originator Port/ {
        ps()
        wwn = $NF
}
$2 ~ /:/ {
        sym = (sym ? sym "," : "") $1
        dir = (dir ? dir "," : "") $2
}
END {   ps()
}' input

If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
# 5  
Old 03-22-2013
Thanks a lot!! this worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert rows to column and print output in required format

Hi All, i am trying to print the solaris 11 packages in below required format, But i am unable to do that. Current ouput : root@abc# pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' NAME: QLogic 570x/571x Gigabit Ethernet Driver VERSION: 11.11,REV=2009.11.11 ... (7 Replies)
Discussion started by: balu1234
7 Replies

2. UNIX for Beginners Questions & Answers

Read line and print output

need help to print the below .. Content of file looks like below .. SCHEMA1. TABLE1 SCHEMA2. TABLE2 SCHEMA3. TABLE3 read lines from above file and print o/p as below print output like read 1st line and print SELECT SCHEMA1.TABLE1 print output like read 2st line and print ... (4 Replies)
Discussion started by: rocking77
4 Replies

3. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

4. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

5. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

6. Shell Programming and Scripting

Read a text file and print the content..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... ... (7 Replies)
Discussion started by: samupnl
7 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

9. Shell Programming and Scripting

Net::SSH::Perl ...... how to print the output in a proper format

Hi Guys, my $cmd = "ls -l"; #........ {or let it be as # my $cmd= "ls"; } my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output getting displayed in a... (7 Replies)
Discussion started by: gsprasanna
7 Replies

10. UNIX for Dummies Questions & Answers

format output from while read line

I have an output that I get from while read, I want to display it as the following, please help. Original output from while read line loop: This is my client=1 client version=2.3.4 OS version=4.5 This is my client=2 client version=1.5.6 OS version=6.7 I want it to look like this with... (7 Replies)
Discussion started by: dala
7 Replies
Login or Register to Ask a Question