How to convert irregular lines into formatted column using awk in windows2003 server environment?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to convert irregular lines into formatted column using awk in windows2003 server environment?
# 1  
Old 04-08-2010
How to convert irregular lines into formatted column using awk in windows2003 server environment?

Dear experts,

I'm newbie to awk scripting. Need your great help to convert the irregular lines into column using awk in windows2003 server environment. (Sorting based on "Pri Number" column)



Code:
 
Input files is as follows:
 
 
Partition Name:    OA
Partition UID:     88:93:22:AE:B3:42:DF:11:A8:64:00:60:16:36:04:02
HBA/SP Pairs:
  HBA UID                                          SP Name     SPPort
  -------                                          -------     ------ 
  50:01:43:80:04:C4:28:81:50:01:43:80:04:C4:28:80   SP A         0
Host name:             OA_02
  50:01:43:80:04:C4:28:81:50:01:43:80:04:C4:28:80   SP B         1
Host name:             OA_02
  50:01:43:80:04:C4:28:83:50:01:43:80:04:C4:28:82   SP B         0
Host name:             OA_02
  50:01:43:80:04:C4:28:83:50:01:43:80:04:C4:28:82   SP A         1
Host name:             OA_02
  50:01:43:80:04:C4:28:83:50:01:43:80:04:C4:28:82   SP B         2
Host name:             OA_02
  50:01:43:80:04:C4:28:83:50:01:43:80:04:C4:28:82   SP A         3
Host name:             OA_02
Pri/Sec Pairs:
  Pri Number      Sec Number
  ----------      ----------
    1                 12
    0                 11
Shareable:             YES
Partition Name:    Test_HA
Partition UID:     32:0A:16:A4:B3:42:DF:11:A8:64:00:60:16:36:04:02
HBA/SP Pairs:
  HBA UID                                          SP Name     SPPort
  -------                                          -------     ------ 
  50:01:43:80:04:C4:28:43:50:01:43:80:04:C4:28:42   SP A         0
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:43:50:01:43:80:04:C4:28:42   SP B         1
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:43:50:01:43:80:04:C4:28:42   SP A         2
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:43:50:01:43:80:04:C4:28:42   SP B         3
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:41:50:01:43:80:04:C4:28:40   SP B         0
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:41:50:01:43:80:04:C4:28:40   SP A         1
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:41:50:01:43:80:04:C4:28:40   SP B         2
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:41:50:01:43:80:04:C4:28:40   SP A         3
Host name:             Test_HA_01
  50:01:43:80:04:C4:28:1B:50:01:43:80:04:C4:28:1A   SP B         0
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:1B:50:01:43:80:04:C4:28:1A   SP A         1
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:1B:50:01:43:80:04:C4:28:1A   SP B         2
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:1B:50:01:43:80:04:C4:28:1A   SP A         3
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:19:50:01:43:80:04:C4:28:18   SP A         0
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:19:50:01:43:80:04:C4:28:18   SP B         1
Host name:            Test_HA_02
  50:01:43:80:04:C4:28:19:50:01:43:80:04:C4:28:18   SP A         2
Host name:             Test_HA_02
  50:01:43:80:04:C4:28:19:50:01:43:80:04:C4:28:18   SP B         3
Host name:             Test_HA_02
Pri/Sec Pairs:
  Pri Number      Sec Number
  ----------      ----------
    3                 2
    4               4
    0               1
    1              3
    5              6
    2              5
Shareable:             YES
Partition Name:    File
Partition UID:     89:93:22:AE:B3:42:DF:11:A8:64:00:60:16:36:04:02
HBA/SP Pairs:
  HBA UID                                          SP Name     SPPort
  -------                                          -------     ------ 
  20:00:00:1B:32:92:32:B6:21:00:00:1B:32:92:32:B6   SP B         0
Host name:             File_01
  20:00:00:1B:32:92:32:B6:21:00:00:1B:32:92:32:B6   SP A         1
Host name:             File_01
  20:00:00:1B:32:92:32:B6:21:00:00:1B:32:92:32:B6   SP B         2
Host name:             File_01
  20:00:00:1B:32:92:32:B6:21:00:00:1B:32:92:32:B6   SP A         3
Host name:             File_01
  20:00:00:1B:32:92:1D:60:21:00:00:1B:32:92:1D:60   SP A         0
Host name:             File_01
  20:00:00:1B:32:92:1D:60:21:00:00:1B:32:92:1D:60   SP B         1
Host name:             File_01
  20:00:00:1B:32:92:1D:60:21:00:00:1B:32:92:1D:60   SP A         2
Host name:             File_01
  20:00:00:1B:32:92:1D:60:21:00:00:1B:32:92:1D:60   SP B         3
Host name:            File_01
Pri/Sec Pairs:
  Pri Number     Sec Number
  ----------     ----------
    2               8
    0               7
    3               10
    1               9
Shareable:             YES
 
 
What I want is: (Sorting based on "Pri Number" column)
 
 
Output like this:
Partition Name    Partition UID         Host Name  Pri Number Sec Number Shareable
------------------ ------------------ --------------  --------------- ---------------- ------------
OA                  88:93...:02 OA_02                           0  11  Yes
OA                  88:93...:02 OA_02                           1  12  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     0  1  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     1  3  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     2  5  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     3  2  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     4  4  Yes
Test_HA          32:0A...:02 Test_HA_01/Test_HA_02     5  6  Yes
File                  89:93...:02 File_01                           0  7  Yes
File                  89:93...:02 File_01                           1  9  Yes
File                  89:93...:02 File_01                           2  8  Yes
File                  89:93...:02 File_01                           3  10  Yes

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk copy first column in new lines

Hi all i have table like this input001_1_174 j 474536 482492 mo001_1_175 j 960192 966656 .ire 966656 984416 .uf/i want copy number of first line to other line... (10 Replies)
Discussion started by: alii
10 Replies

2. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

3. Shell Programming and Scripting

Sed/awk command to convert number occurances into date format and club a set of lines

Hi, I have been stuck in this requirement where my file contains the below format. 20150812170500846959990854-25383-8.0.0 "ABC Report" hp96880 "4952" 20150812170501846959990854-25383-8.0.0 End of run 20150812060132846959990854-20495-8.0.0 "XYZ Report" vg76452 "1006962188"... (6 Replies)
Discussion started by: Chinmaya Kabi
6 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. UNIX for Dummies Questions & Answers

Awk: convert rows to columns every n lines

Hi guys! I use AWK commands under GAMS to predispose the data files to be read by GAMS. I have a file which contains groups of data I need. Unfortunately I have the data spread in 3 rows for each subject. Here's an example (the file is really long) 1 0 2.0956 100.00 250.00 100.00 2.0956... (4 Replies)
Discussion started by: Pintug
4 Replies

6. Shell Programming and Scripting

awk or sed - Convert 2 lines to 1 line

Hi, Just trying to get to grips with sed and awk for some reporting for work and I need some assistance: I have a file that lists policy names on the first line and then on the second line whether the policy is active or not. Policy Name: Policy1 Active: yes Policy... (8 Replies)
Discussion started by: guinch
8 Replies

7. UNIX for Dummies Questions & Answers

awk: convert column to row in a specific way

Hi all! I have this kind of output: a1|b1|c1|d1|e1 a2|b2|c2 a3|b3|c3|d3 I would like to transpose columns d and e (when they exist) in column c, and under the row where they come from. Then copying the beginning of the row. In order to obtain: a1|b1|c1 a1|b1|d1 a1|b1|e1 a2|b2|c2... (1 Reply)
Discussion started by: lucasvs
1 Replies

8. Shell Programming and Scripting

Help: how to convert perl script to awk in windows2003 server environment

For the following perl script, can anyone help to convert it to awk statement in windows2003 server environment ? Code: foreach $k (sort {$a <=> $b} keys %psnum) (1 Reply)
Discussion started by: tojzz
1 Replies

9. Shell Programming and Scripting

awk convert from line to column

i have an output like this : 012008 25760883 022008 12273095 032007 10103 032008 10115642 042007 20952798 but i would like to have it like this 012008,25760883 022008,12273095 032007,10103 032008,10115642 042007,20952798 (4 Replies)
Discussion started by: jarmouda
4 Replies

10. Shell Programming and Scripting

Convert DATE string to a formatted text

Hi guys, i need your help. I need to convert a date like this one 20071003071023 , to a formated date like 20071003 07:10:23 . Could this be possible ? Regards, Osramos (6 Replies)
Discussion started by: osramos
6 Replies
Login or Register to Ask a Question