need to insert two columns (or two feilds) at the begining of the table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to insert two columns (or two feilds) at the begining of the table
# 1  
Old 10-22-2008
Question need to insert two columns (or two feilds) at the begining of the table

Hey guys/gals,

So here is what i'm starting with...its a Solaris patch diag output.

bash-3.0# pca -l
Using /var/tmp/patchdiag.xref from Oct/20/08
Host: seiftsx4140 (SunOS 5.10/Generic_127128-11/i386/i86pc)
List: missing

Patch IR CR RSB Age Synopsis
------ -- - -- --- --- -------------------------------------------------------
119255 53 < 59 RS- 21 SunOS 5.10_x86: Install and Patch Utilities Patch
118668 15 < 17 -S- 106 JavaSE 5.0_x86: update 16 patch (equivalent to JDK 5.0u16)
118736 01 < 02 --- 153 SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch
118825 01 < 02 --- 152 SunOS 5.10_x86: sort patch
119043 10 < 11 R-- 140 SunOS 5.10_x86: svccfg & svcprop patch
119060 39 < 44 RS- 82 X11 6.6.2_x86: Xsun patch
119091 26 < 32 R-- 42 SunOS 5.10_x86: Sun iSCSI Device Driver and Utilities
119214 16 < 17 -S- 231 NSS_NSPR_JSS 3.11.9_x86: NSPR 4.7 / NSS 3.11.9 / JSS 4.2.6
119247 32 < 34 R-- 61 SunOS 5.10_x86: Manual Page updates for Solaris 10
119253 25 < 29 R-- 22 SunOS 5.10_x86: System Administration Applications Patch
119281 17 < 18 --- 141 CDE 1.6_x86: Runtime library patch for Solaris 10
119398 06 < 07 --- 107 SunOS 10_x86: Patch for North America Region locale issues
--------------------------------------
I then run this...
Code:
pca -l | awk '{print $1";"$2";"$4";"$5";"$6";"$7,$8,$9,$10,$12,$15,$16,$18,$19,$20,$21,$22}' |sed -e '1,6 d'

--------------------------------------
and I get this in return....

119255;53;59;RS-;21;SunOS 5.10_x86: Install and Utilities
118668;15;17;-S-;106;JavaSE 5.0_x86: update 16 (equivalent 5.0u16)
118736;01;02;---;153;SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch
118825;01;02;---;152;SunOS 5.10_x86: sort patch
119043;10;11;R--;140;SunOS 5.10_x86: svccfg & patch
119060;39;44;RS-;82;X11 6.6.2_x86: Xsun patch
119091;26;32;R--;42;SunOS 5.10_x86: Sun iSCSI Driver
119214;16;17;-S-;231;NSS_NSPR_JSS 3.11.9_x86: NSPR 4.7 NSS JSS 4.2.6
119247;32;34;R--;61;SunOS 5.10_x86: Manual Page for
119253;25;29;R--;22;SunOS 5.10_x86: System Administration Patch
119281;17;18;---;141;CDE 1.6_x86: Runtime library for
119398;06;07;---;107;SunOS 10_x86: Patch for America issues
-----------------------------------------
what I'm doing is dumping this into a mysqlDB, however I think i need to add date and hostname fields to link table in my php frontend. So, Is there a way to make the output look like this...

$hostname;$date;119255;53;59;RS-;21;SunOS 5.10_x86: Install and Utilities
$hostname;$date;118668;15;17;-S-;106;JavaSE 5.0_x86: update 16 (equivalent 5.0u16)
$hostname;$date;118736;01;02;---;153;SunOS 5.10_x86: usr/sbin/rpc.nisd_resolv Patch
# 2  
Old 10-22-2008
Depending on the seperation character (we can't see it here unless you use [ C O D E ] tags) you might be able to use cut or sed here, but I'm assuming it's some variable length whitespace or a tab char, so:
Code:
pca -l | tail +7 | while read line
do
  echo $hostname `date` `echo $line | awk '{print $1";"$2";"$4";"$5";"$6";"$7,$8,$9,$10,$12,$15,$16,$18,$19,$20,$21,$22}'`
done

There's far nicer ways to print out fields 1,2,4,5,6 and 7 with ; seperators followed by all remaining fields.
There's also ways to get awk to display the date and hostname.
But this should do the job (not that I tested it though, so be a tad careful Smilie )

Last edited by Smiling Dragon; 10-22-2008 at 06:42 PM.. Reason: Forgot the trailing backtick
# 3  
Old 10-22-2008
Hi Dragon,

my seperator is ';' (semi-colon)

Also, is there a better way to tell AWK to print all columns except column $3 ?

Thanks so much for you help!...i'll try this out
# 4  
Old 10-22-2008
Thanks Dragon,

my seperator is ";" (semi-colon)

I'll give this syntax a try...

Also, would you know how to tell AWK to print every column EXCEPT column $3 ?

I could not figure that out...so that is why I defined so many print arguments in the statement...

Thanks again for all your help!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

1. This will insert the records into db table by reading from ta csv file

I have this code with me but the condition is If any of the mandatory columns are null then entire file will be rejected. LOAD DATA infile ' ' #specifies the name of a datafile containing data that you want to load BADFILE ' ' #specifies the name of... (1 Reply)
Discussion started by: raka123
1 Replies

2. Shell Programming and Scripting

Insert one table and update another with shellscript

I have a problem with my shell script. I want to insert data from file to table1(empty) and then, compare table1 with table2 and update some fields. The first part is correct, but the second part does not work. The only way it works is if after the first part I truncate table1 and run the script... (1 Reply)
Discussion started by: nika_mill
1 Replies

3. Shell Programming and Scripting

Insert bulk values in DB table using isql

Hello, Objective is to insert bulk values in DB table using isql. Following code tried: isql -SServer_name -Ddb_name -Uuser_name -Ppassword < file.txt cat file.txt for i in `cat data_value_file.txt` do insert into tempdb..temp_table11 values ('$i') go done cat... (3 Replies)
Discussion started by: manishdivs
3 Replies

4. Programming

Table Locking in Insert Command.

Hi, i have a java based tool which does insert operation in a TABLE, and in parallel the same table is used by my C++ code which does select Query. the Table will be always busy, but sometimes the table is getting locked when i try to make an insert, am bit confused whether the lock is... (0 Replies)
Discussion started by: senkerth
0 Replies

5. Shell Programming and Scripting

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

6. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

7. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

8. Shell Programming and Scripting

Insert value to ORACLE table from sqlldr log

This is the sample sqlldr log: ------------------------------------------------------------------------------------------------------------ SQL*Loader: Release 9.2.0.7.0 - Production on Sun Feb 8 23:37:02 2009 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Control... (13 Replies)
Discussion started by: aimy
13 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Programming

Insert Text at begining of file

Hi All, Its been a long time since i did any programming and I am trying to get back into it as part of also learning Linux. Coming from a Cpp background i am trying to write some simple code just using C. I want to create a simple log file but instead of appending to the end of the file i... (3 Replies)
Discussion started by: netwolf
3 Replies
Login or Register to Ask a Question