updating a column in a unix table for a particular row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting updating a column in a unix table for a particular row
# 1  
Old 04-26-2005
updating a column in a unix table for a particular row

Hi,
I have the following requirement.
I have a unix table as below

progname par1 par2 par3 par4
PROG1 abc def 0012 ooo
PROG2 wed xas 0100 xxx
PROG3 kkk ppp 0004 ppp

Different programs(ex:PROG1,PROG2..) accesses this table and update par3, corresponding to this progname... (i.e, when PROG1 is running, it updates it's corresponding par3 to 0013, similarly for other programs).. How can I achive this updation of par3 column for a particular row corresponding to that program thru shell scripting in a easy way)

After program PROG1 runs, the above table should look like
progname par1 par2 par3 par4
PROG1 abc def 0013 ooo
PROG2 wed xas 0100 xxx
PROG3 kkk ppp 0004 ppp

if PROG3 runs later then the table should look like
progname par1 par2 par3 par4
PROG1 abc def 0013 ooo
PROG2 wed xas 0100 xxx
PROG3 kkk ppp 0005 ppp


Can someone helpme out how this file column updation for a particular row can be achieved easily thru shell scripting.
Thanks for any of your inputs...
# 2  
Old 04-26-2005
Try...
Code:
awk '$1==p{$4=sprintf("%04d",$4+1)};1' p=PROG2 file1 > file2

# 3  
Old 04-26-2005
syntax error...

Iam getting below syntax error ( Using Sunsolaris)

awk '$1==p{$4=sprintf("%04d",$4+1)};1' p=PROG2 table > table1
awk: syntax error near line 1
awk: bailing out near line 1

Something to be changed in the command...
# 4  
Old 04-26-2005
Replace awk with nawk.

Cheers
ZB
# 5  
Old 04-26-2005
nawk '$1==p{$4=sprintf("%04d",$4+1)};1' p=PROG2 table > table
Hi if I use the command like above, the table is erased totally

nawk '$1==p{$4=sprintf("%04d",$4+1)};1' p=PROG2 table > table1
it writes into a new table table1.. then I need to overwrite table1 with table

But if two programs are running simultaneourly, I don't know, if this works fine.
# 6  
Old 02-09-2009
In general it's a bad idea to redirect the output of a filter (unix command) to the input as it usually results in and empty file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using loop command in UNIX for converting column to row

Dear folks I have 300 files which one of them are looking like: 1.SNP 0 0 1 0 I am looking for desire output: 1.SNP 0 0 1 0 I used this below command to run all of the 300 file at the same time for file in *.SNP; do awk '{printf( "%s ", $1 );} END {printf("\n");}' $file >... (1 Reply)
Discussion started by: sajmar
1 Replies

2. Shell Programming and Scripting

awk to convert table-by-row to matrix table

Hello, I need some help to reformat this table-by-row to matrix? infile: site1 A:o,p,q,r,s,t site1 C:y,u site1 T:v,w site1 -:x,z site2 A:p,r,t,v,w,z site2 C:u,y site2 G:q,s site2 -:o,x site3 A:o,q,s,t,u,z site3 C:y site3 T:v,w,x site3 -:p,routfile: SITE o p q r s t v u w x y... (7 Replies)
Discussion started by: yifangt
7 Replies

3. Shell Programming and Scripting

In php, Moving a new row to another table and deleting old row

Hi, I already succeed moving a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). But it can't delete the old row. Please help me with the script. my php script: INSERT INTO... (2 Replies)
Discussion started by: jazzyzha
2 Replies

4. Shell Programming and Scripting

Moving new row and deleting old row to another table

Hi, I want to move a new row to another table if the field from new row doesn't have the first word that I categorized (like: IRC blablabla, PTM blablabla, ADM blablabla, BS blablabla). I already use this script but doesn't work as I expected. CHECK_KEYWORD="$( mysql -uroot -p123456 smsd -N... (7 Replies)
Discussion started by: jazzyzha
7 Replies

5. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

6. Shell Programming and Scripting

Unix path stored as a column in table

The db2 table stores the unix path as below PARM VALUE RootPath $SRootDir Target $SRootDir/target $SRootDir is set in the env variable as /home/test/root In the shell script i read the table value and store it in a variable pth=db2 -x "select VALUE from... (2 Replies)
Discussion started by: 2jnags
2 Replies

7. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

8. Shell Programming and Scripting

extracting row with max column value using awk or unix

Hello, BC106081_abc_128240811_128241377 7.96301 BC106081_abc_128240811_128241377 39.322 BC106081_cde_128240811_128241377 1.98628 BC106081_def_128240811_128241377 -2.44492 BC106081_abc_128240811_128241377 69.5504 FLJ00075_xyz_14406_16765 -0.173417 ... (3 Replies)
Discussion started by: Diya123
3 Replies

9. UNIX for Dummies Questions & Answers

Updating table on UNIX server using SFTP

Hi, I have a requirement where in I have to connect to an Unix database server using SFTP. After connecting I have to write some data to one of the tables in UNIX. Can anyone tell me the UNIX commands to open and update database table. Thanks, Pallavi (1 Reply)
Discussion started by: Pallavi_gondkar
1 Replies

10. Shell Programming and Scripting

updating a column in oracle table using shell script

Hi friends, i am having a variable declared in .profile.i am changing its value in a shell script and then i am connecting to oracle and then from there i am calling a .sql called update.sql STATUS is the variable declared in the .profile =============================== if sqlplus <<END... (3 Replies)
Discussion started by: sveera
3 Replies
Login or Register to Ask a Question