Manipulate file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulate file
# 1  
Old 11-08-2012
Manipulate file

Hi Guys,
I have a file that lists patches along with other information.
The patches are listed in two different formats.
One format lists the latest patch, date , installed patch
Code:
Latest Patch     Date        IN
148412-02        13-Sep-2012 --  X   X SunOS 5.10: nss_dns patch
126206-10        16-Aug-2012 09  X X X SunOS 5.10: zebra ripd quagga patch

The other format lists the patch as 123456 and then it lists the installed rev , min rev and the latest rev.
Code:
Patch  Date        IN  MIN LAT
119783 19-Oct-2012 21  24  25  X X X SunOS 5.10: BIND patch
120272 24-Aug-2012 31  31  37    X X SunOS 5.10: SMA patch

I want to create a new file that lists all the patches in this format 123456-02.

So the input file looks like this:
Code:
================================================================================
=                         System Overview                                      =
================================================================================
Hostname                          : server1
Hostid                            : 84ec6f30
Machine Description               : Sun SPARC Enterprise T5120 server
Serial Number                     : BEL0838M0K
Explorer Collection Date          : 28-Oct-2012 12:39:00 UTC
Machine Architecture              : sparc
OBP Level                         : 4.30.4
KJP Installed Revision            : 147440-19
================================================================================
=                           Withdrawn Patches                                  =
================================================================================
================================================================================
=                           Recommended Patches                                =
================================================================================
148412-02 13-Sep-2012 --  X   X SunOS 5.10: nss_dns patch
126206-10 16-Aug-2012 09  X X X SunOS 5.10: zebra ripd quagga patch
125137-39 15-Oct-2012 35  X X   JavaSE 6: update 37 patch (equivalent to JDK 
149483-01 16-Aug-2012 --  X X   SunOS 5.10: Foomatic patch
146470-08 14-Sep-2012 06  X   X SunOS 5.10: timezone patch
146032-05 28-Sep-2012 03  X X   SunOS 5.10: perlbug patch
146489-06 10-May-2012 05  X   X SunOS 5.10: qlc patch
145006-03 18-Jun-2012 02  X X   SunOS 5.10: Webmin patch
141596-10 10-Oct-2012 01  X X X SunOS 5.10: UFS file system utilities patch
149149-01 07-Aug-2012 --  X X   SunOS 5.10: LP Alerts Patch
146486-04 13-Sep-2012 03  X X X SunOS 5.10: vlds patch
138822-11 03-Oct-2012 09  X X   SunOS 5.10: PostgreSQL 8.3 documentation patch
137147-07 27-Jul-2012 06  X X   SunOS 5.10: libexpat patch
126546-04 14-Sep-2012 01  X X   SunOS 5.10: bash patch
147805-01 26-Apr-2012 --  X   X SunOS 5.10: tl patch
147790-01 26-Apr-2012 --  X     SunOS 5.10: fmd patch
================================================================================
=                           Security Patches                                   =
================================================================================
119783 19-Oct-2012 21  24  25  X X X SunOS 5.10: BIND patch
120272 24-Aug-2012 31  31  37    X X SunOS 5.10: SMA patch
122958 09-Apr-2010 05  --  06    X   GNOME 2.6.0: RealPlayer media application
147378 15-Mar-2012 01  01  02    X   SunOS 5.10: zip patch
146666 16-Aug-2012 04  04  11    X X SunOS 5.10: lp patch
125279 06-Aug-2012 05  05  06    X   CDE 1.6: dtsession patch
149483 16-Aug-2012 --  01  01  X X   SunOS 5.10: Foomatic patch
119059 05-Jul-2012 61  61  62    X X X11 6.6.2: Xsun patch
122259 02-Jul-2012 05  06  06  X X   SunOS 5.10: SunFreeware gnu esp 
118666 15-Oct-2012 38  32  40  X X   JavaSE 5.0: update 38 patch (equivalent 
120185 15-Mar-2011 16  --  23    X   StarOffice 8 (Solaris): Update 18
147004 17-Feb-2012 --  --  04    X X SunOS 5.10: ehci patch
146664 15-Oct-2012 --  --  02    X   SunOS 5.10: r(cmd) patch
148601 12-Jul-2012 01  01  02    X X SunOS 5.10: sockfs patch
149106 05-Oct-2012 --  01  01  X X   SunOS 5.10: 
================================================================================
=                         Critical Patch Updates                               =
================================================================================
119783 19-Oct-2012 21  24  25  X X X SunOS 5.10: BIND patch
126119 07-Aug-2012 01  02  02  X X   CDE 1.6: sys-suspend patch
147159 12-Oct-2012 03  05  08    X X SunOS 5.10: T4 crypto performance patch
146578 27-Oct-2011 --  --  06    X   SunOS 5.10: compress cp cpio ln mv pack 
149149 07-Aug-2012 --  01  01  X X   SunOS 5.10: LP Alerts Patch
146232 01-Oct-2012 --  --  21    X   SunOS 5.10: iSCSI patch
147155 10-Oct-2012 --  02  03    X X SunOS 5.10: ldc patch
149395 19-Oct-2012 --  --  01    X   SunVTS 7.0: Patch Set 15 consolidation 
137080 18-Jul-2012 06  07  07  X X   SunOS 5.10: libpng Patch
147004 17-Feb-2012 --  --  04    X X SunOS 5.10: ehci patch
119810 17-Jul-2012 05  07  07  X X   SunOS 5.10: International Components for 
146664 15-Oct-2012 --  --  02    X   SunOS 5.10: r(cmd) patch
149106 05-Oct-2012 --  01  01  X X   SunOS 5.10: 
================================================================================
=                             ASP Patches                                      =
================================================================================
121308-23 10-May-2012 20    X   SunOS 5.10: Solaris Management Console Patch
118777-18 17-May-2012 16    X X SunOS 5.10: Sun GigaSwift Ethernet 1.0 driver 
146489-06 10-May-2012 05  X   X SunOS 5.10: qlc patch
146578-06 27-Oct-2011 --    X   SunOS 5.10: compress cp cpio ln mv pack pax 
119246-40 02-Aug-2012 39        SunOS 5.10: Manual Page updates for Solaris 10
119252-35 16-Aug-2012 29    X X SunOS 5.10: System Administration Applications 
137097-02 10-Oct-2012 01  X X   SunOS 5.10: inetd-upgrade patch
149395-01 19-Oct-2012 --    X   SunVTS 7.0: Patch Set 15 consolidation patch
================================================================================
=                           Sun/Oracle Alert Patches                           =
================================================================================
120185 15-Mar-2011 16  17  23    X   StarOffice 8 (Solaris): Update 18
124672 12-Mar-2012 --  13  20    X   Application Server Enterprise Edition 
125541 15-Dec-2009 04  06  06    X   Mozilla 1.7: Mozilla Thunderbird email 
147440 10-Oct-2012 19  22  25  X X X SunOS 5.10: Solaris kernel patch
147805 26-Apr-2012 --  01  01  X   X SunOS 5.10: tl patch
================================================================================
=                        Sun/Oracle Alert Security Patches                     =
================================================================================
120185 15-Mar-2011 16  17  23    X   StarOffice 8 (Solaris): Update 18
124672 12-Mar-2012 --  13  20    X   Application Server Enterprise Edition 
125541 15-Dec-2009 04  06  06    X   Mozilla 1.7: Mozilla Thunderbird email 
147440 10-Oct-2012 19  22  25  X X X SunOS 5.10: Solaris kernel patch
================================================================================
=              HOST BUS ADAPTERS (HBAs) Found on this System                   =
================================================================================
137137-09 10-Nov-2008 09  X X X SunOS 5.10: kernel patch
139555-08 07-May-2009 08  X X X SunOS 5.10: Kernel Patch
141444-09 13-Oct-2009 09  X X X SunOS 5.10: kernel patch
142909-17 07-Sep-2010 17  X X X SunOS 5.10: kernel patch
123305-04 15-Dec-2008 --      X Hardware/FCode: PCI-X/PCI Express Dual or 
123305-04 15-Dec-2008 --      X Hardware/FCode: PCI-X/PCI Express Dual or 
144112-02 02-Nov-2011 02  X     SunOS 5.10: liba5k patch
119130-33 14-Feb-2007 33  X   X SunOS 5.10: Sun Fibre Channel Device Drivers

I want the output file to look like this:
Code:
================================================================================
=                         System Overview                                      =
================================================================================
Hostname                          : server1
Hostid                            : 84ec6f30
Machine Description               : Sun SPARC Enterprise T5120 server
Serial Number                     : BEL0838M0K
Explorer Collection Date          : 28-Oct-2012 12:39:00 UTC
Machine Architecture              : sparc
OBP Level                         : 4.30.4
KJP Installed Revision            : 147440-19
================================================================================
=                           Withdrawn Patches                                  =
================================================================================
================================================================================
=                           Recommended Patches                                =
================================================================================
148412-02
126206-10
125137-39
149483-01
146470-08
146032-05
146489-06
145006-03
141596-10
149149-01
146486-04
138822-11
137147-07
126546-04
147805-01
147790-01
================================================================================
=                           Security Patches                                   =
================================================================================
119783-25
120272-37
122958-06
147378-02
146666-11
125279-06
149483-01
119059-62
122259-06
118666-40
120185-23
147004-04
146664-02
148601-02
149106-01
================================================================================
=                         Critical Patch Updates                               =
================================================================================
119783-25
126119-02
147159-08
146578-06
149149-01
146232-21
147155-03
149395-01
137080-07
147004-04
119810-07
146664-02
149106-01
================================================================================
=                             ASP Patches                                      =
================================================================================
121308-23
118777-18
146489-06
146578-06
119246-40
119252-35
137097-02
149395-01
================================================================================
=                           Sun/Oracle Alert Patches                           =
================================================================================
120185-23
124672-20
125541-06
147440-25
147805-01
================================================================================
=                        Sun/Oracle Alert Security Patches                     =
================================================================================
120185-23
124672-20
125541-06
147440-25
================================================================================
=              HOST BUS ADAPTERS (HBAs) Found on this System                   =
================================================================================
123305-04
123305-04

Also please note that some patches at the end of the first file do not appear in the second file as the patch rev is the same as what is installed.
The script can be a sh, bash or a ksh script, what ever you prefer.
Tornado
# 2  
Old 11-08-2012
Code:
awk '/^[0-9]/  {var=(index($1,"-")>0) ? $1 : $1 "-" $5; print var ;next}
                      {print $0} '  file1 file2 > newfile

Try that.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-08-2012
Thanks Jim.
Thats great, it does the bulk of the work that I wanted.
It doesn't strip the patches that are already installed(the ones at the end), But I think I can sort that bit out.

Once again this site has saved me.
Much appreciated.

Last edited by Tornado; 11-08-2012 at 10:37 PM..
Tornado
# 4  
Old 11-08-2012
This does everything you want to be done.
Code:
awk '/^[0-9]+/{
if((n=split($1,a,/-/))>1) {
 if(a[n]==$3) next
 $0=$1
} else {
 if($3==$5) next
 $0 = $1 "-" $5
}
}1' infile


Last edited by elixir_sinari; 11-08-2012 at 11:01 PM..
# 5  
Old 11-08-2012
You tried it and it does not.

Hmm. very interesting.

This is the output I got (name is newfile )
Code:
================================================================================
=                         System Overview                                      =
================================================================================
Hostname                          : server1
Hostid                            : 84ec6f30
Machine Description               : Sun SPARC Enterprise T5120 server
Serial Number                     : BEL0838M0K
Explorer Collection Date          : 28-Oct-2012 12:39:00 UTC
Machine Architecture              : sparc
OBP Level                         : 4.30.4
KJP Installed Revision            : 147440-19
================================================================================
=                           Withdrawn Patches                                  =
================================================================================
================================================================================
=                           Recommended Patches                                =
================================================================================
148412-02
126206-10
125137-39
149483-01
146470-08
146032-05
146489-06
145006-03
141596-10
149149-01
146486-04
138822-11
137147-07
126546-04
147805-01
147790-01
================================================================================
=                           Security Patches                                   =
================================================================================
119783-25
120272-37
122958-06
147378-02
146666-11
125279-06
149483-01
119059-62
122259-06
118666-40
120185-23
147004-04
146664-02
148601-02
149106-01
================================================================================
=                         Critical Patch Updates                               =
================================================================================
119783-25
126119-02
147159-08
146578-06
149149-01
146232-21
147155-03
149395-01
137080-07
147004-04
119810-07
146664-02
149106-01
================================================================================
=                             ASP Patches                                      =
================================================================================
121308-23
118777-18
146489-06
146578-06
119246-40
119252-35
137097-02
149395-01
================================================================================
=                           Sun/Oracle Alert Patches                           =
================================================================================
120185-23
124672-20
125541-06
147440-25
147805-01
================================================================================
=                        Sun/Oracle Alert Security Patches                     =
================================================================================
120185-23
124672-20
125541-06
147440-25
================================================================================
=              HOST BUS ADAPTERS (HBAs) Found on this System                   =
================================================================================
137137-09
139555-08
141444-09
142909-17
123305-04
123305-04
144112-02
119130-33

This is the input file I used:
Code:
================================================================================
=                         System Overview                                      =
================================================================================
Hostname                          : server1
Hostid                            : 84ec6f30
Machine Description               : Sun SPARC Enterprise T5120 server
Serial Number                     : BEL0838M0K
Explorer Collection Date          : 28-Oct-2012 12:39:00 UTC
Machine Architecture              : sparc
OBP Level                         : 4.30.4
KJP Installed Revision            : 147440-19
================================================================================
=                           Withdrawn Patches                                  =
================================================================================
================================================================================
=                           Recommended Patches                                =
================================================================================
148412-02
126206-10
125137-39
149483-01
146470-08
146032-05
146489-06
145006-03
141596-10
149149-01
146486-04
138822-11
137147-07
126546-04
147805-01
147790-01
================================================================================
=                           Security Patches                                   =
================================================================================
119783-25
120272-37
122958-06
147378-02
146666-11
125279-06
149483-01
119059-62
122259-06
118666-40
120185-23
147004-04
146664-02
148601-02
149106-01
================================================================================
=                         Critical Patch Updates                               =
================================================================================
119783-25
126119-02
147159-08
146578-06
149149-01
146232-21
147155-03
149395-01
137080-07
147004-04
119810-07
146664-02
149106-01
================================================================================
=                             ASP Patches                                      =
================================================================================
121308-23
118777-18
146489-06
146578-06
119246-40
119252-35
137097-02
149395-01
================================================================================
=                           Sun/Oracle Alert Patches                           =
================================================================================
120185-23
124672-20
125541-06
147440-25
147805-01
================================================================================
=                        Sun/Oracle Alert Security Patches                     =
================================================================================
120185-23
124672-20
125541-06
147440-25
================================================================================
=              HOST BUS ADAPTERS (HBAs) Found on this System                   =
================================================================================
137137-09
139555-08
141444-09
142909-17
123305-04
123305-04
144112-02
119130-33

This is the code I ran :
Code:
awk '/^[0-9]/  {var=(index($1,"-")>0) ? $1 : $1 "-" $5; print var ;next}
                      {print $0} '  filename  > newfile

If you want help you should be willing to look at and work with the code. We are not a coding service. AND IMO the code does as you asked.

You just reached the endpoint of my largesse.
# 6  
Old 11-08-2012
Quote:
Originally Posted by jim mcnamara

If you want help you should be willing to look at and work with the code. We are not a coding service. AND IMO the code does as you asked.

You just reached the endpoint of my largesse.
I did look at the code you provided and I will use it in my script.
The input file I provided is the result of the first part of my script, I was having problems trying to format that file to look like the output file I provided, So I do appreciate your assistance.

I did say thank you, so not sure why your grumpy.
Tornado
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Manipulate the text file in UNIX

Hi All, I have a file like below and i have 2 questions on this (They are 3 lines starts with 01 , 02 and 03. but is 01abc333644554 234 2334535 34534535355353 sfsdf345455 353 4543 jgkg tty 7676 02cdesdfsdfsdf 234 wesdfsdf 345345 234234 234234 2342342 dfgdfg sdfgg dgdgdg fgvfs... (6 Replies)
Discussion started by: siva.pitchai
6 Replies

2. Shell Programming and Scripting

Manipulate a CSV File

Hello, How do i manipulate .csv file to this format? Thank you very much. Source: john,5 marco,7 john,4 paul,3 marco,8 Output: john,9 marco,15 (5 Replies)
Discussion started by: tara123
5 Replies

3. Shell Programming and Scripting

nawk script to manipulate txt file

Hi experts, I am not familiarised using nawk/awk to manipulate txt file. So I need ur help here. thanks. txt1 - qc_m.log TQC101 TQC102 TQC103 TQC104 txt2 - resultEqpt.log TQC102,,LOGOFF TQC103,,LOGOFF TQC104,2012-10-03 07:42:57,LOGON so TQC101 is not found in txt 2. ... (15 Replies)
Discussion started by: ment0smintz
15 Replies

4. Shell Programming and Scripting

Find string in one file and manipulate other

hi, I have 2 files delimited by "|" File 1: 1|28|ABC|11|9620034||XXX555| 29|22|ABC|11|9620258||XXX555| 51|26|ABC|11|9620314||XXX555| 77|20|ABC|11|9630506||XXX555| 97|36|ABC|11|9630562||XXX555| File 2: 9620028|I 9620034|I 9620314|S 9620332|I 9620258|I 9630506|S 9630562|S (3 Replies)
Discussion started by: pparthiv
3 Replies

5. UNIX for Dummies Questions & Answers

Manipulate and move columns in a file

Hello Unix Gurus, I have a request 2 perform several functions on a file, delete columns, delete rows based on column value, and finally move around columns in the final output. Consider the following input file with 12 columns; ... (1 Reply)
Discussion started by: chumsky
1 Replies

6. Shell Programming and Scripting

Shell script to manipulate a file

Hello, I have a file with following contents : WSL SRVGRP=LISTENER SRVID=2 CLOPT="-A -t -- -n 0x0002aa050a03cc65 " RQPERM=0660 REPLYQ=Y RPPERM=0660 MIN=1 MAX=1 CONV=N I need to print only the value in Hex i.e.... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

7. Shell Programming and Scripting

Extract File line and manipulate

How can I print a section of each line in a text file. Eg CODE1 XYR Test2 10319389 CODE2 XYR Test2 10319389 CODE3 XYR Test2 10319389 CODE4 XYR Test2 10319389 CODE5 XYR Test2 10319389 First thing that would be nice would a new file like, awk sed and substring may help but can't figure it... (6 Replies)
Discussion started by: kelseyh
6 Replies

8. Shell Programming and Scripting

sed script to manipulate the /etc/passwd file

Hi. Can anybody help me with a script to extract usernames, shell and home_directory from the /etc/passwd file. I am stuck (2 Replies)
Discussion started by: Pauline mugisha
2 Replies

9. Shell Programming and Scripting

How do manipulate file path and names

In emacs elisp, there is a handy function called file-name-nondirectory which accepts a path and file name and returns just a file name and extension. There is also a function called file-name-directory which just returns the dire ctory name without the file. How can I implement these same... (2 Replies)
Discussion started by: siegfried
2 Replies

10. Filesystems, Disks and Memory

manipulate csv file to add columns

Hi, I have a csv file with a key composed by 3 columns and some other numeric fields and I need to obtain the partial amounts by some part of the key. This may be some difficult to understand, so better see an example, where my input file is: name,surname,department,y2004,y2005,y2006... (6 Replies)
Discussion started by: oscarmon
6 Replies
Login or Register to Ask a Question