Add column and update file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add column and update file
# 1  
Old 03-30-2012
Bug Add column and update file

I have to update my file from server file.

Server file A on location

Code:
serverfile="/orf/ddl/plokall/fileA"
myfile=""/orf/ddl/plokall/myupdatedfile"

fileA:



Code:
KALKIKLOKPO001	10.1
HFJFKSLOKPO002  11.4	
POLKAK5143 184.3	
POLKJI5144 107.5	
OKILDL5145 107.10
CVT0909 10.11
KJL0405 09.32
PPOIKIJIJ1011 09.09	
SNJNPRU0410 10.22

I want output in my file


Code:
KALKIKLOKPO001	10.1	ppc01
HFJFKSLOKPO002  11.4	ppc02	
POLKAK5143 184.3	lcc5143	
POLKJI5144 107.5	lcc5144	
OKILDL5145 107.10	lcc5145
CVT0909 10.11	lcc0909
KJL0405 09.32	lcc0405
PPOIKIJIJ10L11 09.09	ppc11
SNJNPRU0410 10.22	lcc0410


My logic is if the last four digit of 1st column is number the i want 3rd column is "lcc" & lastfour digit else "ppc" & last 2 digit"

last four digit of column A....

Thanks in advace
# 2  
Old 03-30-2012
Hi asavaliya,

One way with perl:
Code:
$ cat infile
KALKIKLOKPO001  10.1
HFJFKSLOKPO002  11.4
POLKAK5143 184.3
POLKJI5144 107.5
OKILDL5145 107.10
CVT0909 10.11
KJL0405 09.32
PPOIKIJIJ1011 09.09
SNJNPRU0410 10.22
$ perl -ane '$F[2] = $F[0] =~ m/\D(\d{4})\Z/ ? qq[lcc$1] : $F[0] =~ m/(\d{2})\Z/ ? qq[ppc$1] : qq[] ; printf qq[%s\n], join qq[\t], @F' infile
KALKIKLOKPO001  10.1    ppc01
HFJFKSLOKPO002  11.4    ppc02
POLKAK5143      184.3   lcc5143
POLKJI5144      107.5   lcc5144
OKILDL5145      107.10  lcc5145
CVT0909 10.11   lcc0909
KJL0405 09.32   lcc0405
PPOIKIJIJ1011   09.09   lcc1011
SNJNPRU0410     10.22   lcc0410

# 3  
Old 03-30-2012
Thanks..but ..I want to use shell scripting....
# 4  
Old 03-30-2012
Code:
awk '{       S=substr($1, length($1)-3);
        $(NF+1)=(S ~/^[0-9]+$/ ? "lcc" S : "ppc" substr($1,length($1)-1)); } 1' data

KALKIKLOKPO001 10.1 ppc01
HFJFKSLOKPO002 11.4 ppc02
POLKAK5143 184.3 lcc5143
POLKJI5144 107.5 lcc5144
OKILDL5145 107.10 lcc5145
CVT0909 10.11 lcc0909
KJL0405 09.32 lcc0405
PPOIKIJIJ1011 09.09 lcc1011
SNJNPRU0410 10.22 lcc0410

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add new column in the file

Hi Team I have file as below empno,ename,sal 123,smith,1000 124,adams,2000 Required output: Using AWK empno,ename,sal,deptno 123,smith,1000 124,adams,2000 Thanks, Murali (5 Replies)
Discussion started by: bmk
5 Replies

2. UNIX for Dummies Questions & Answers

Add a column to a file

Hi, I have this data file that contains: 1 A 2 B 3 C 4 D 5 E 6 F 7 G 8 H 9 I I want the results to be: 1 A A 2 B A 3 C A 4 D A 5 E A 6 F A 7 G A 8 H A (8 Replies)
Discussion started by: bobo
8 Replies

3. Shell Programming and Scripting

Add a new column to file

I have file like this b,c 10,20 30,40 50,60 Now I want to add a new column a with fixed values for all the rows a,b,c 60,10,20 60,30,40 60,50,60 Please let me know how can we do this in unix. (4 Replies)
Discussion started by: weknowd
4 Replies

4. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

Update column in File

I Have a file a.txt in the below format 1 23 50 1 25 6666666666666 1 23 34 If the third column value is greater than two digit then make it 0 New Data File --------------- a.txt 1 23 50 1 25 0 1 23 34 Need your help regarding this (5 Replies)
Discussion started by: deep_kol
5 Replies

6. Shell Programming and Scripting

How to add a column from other file?

Dear all, Lets say, I've a file a.txt containing two columns, like a1 b1 .. .. .. .. and another file b.txt containg two columns, like a1 c1 .. .. .. .. I need to put c1 column from b.txt file to the a.txt file. So, the output should be a1 b1 c1 .. .. .. .. ... (4 Replies)
Discussion started by: mkg
4 Replies

7. Shell Programming and Scripting

Add column to a file

Hola, How can I add a column to a existing file?? PS: The column which should be added need to be the first column and it will be a parameter from the script. Example: 1 name1 2 name2 3 name3 4 name3 Need to add parameter $file as a first column. $file is a file name with time... (6 Replies)
Discussion started by: Olivia
6 Replies

8. Shell Programming and Scripting

Need to add letters to a column and add in a new column subtracting from another column

So I have this input 1 10327 rs112750067 T C . PASS DP=65;AF=0.208;CB=BC,NCBI 1 10469 rs117577454 C G . PASS DP=2055;AF=0.020;CB=UM,BC,NCBI 1 10492 rs55998931 C T . PASS DP=231;AF=0.167;CB=BC,NCBI 1 10583 rs58108140 G A ... (3 Replies)
Discussion started by: kellywilliams
3 Replies

9. Shell Programming and Scripting

Update file to add as last column

I need to update a text file within a loop so that the value is added creating a new column at the end. I cannot use paste because I dont know the number of files. If I use >> the value is added after the last row. Please help. For example: Input file: Column 1 Column2 - ... (2 Replies)
Discussion started by: Surabhi_so_mh
2 Replies

10. Shell Programming and Scripting

How to add a particular column alone in a file

Hi I have file which contains 5 coulmns i need to add the fifth column value and put it in the desired location in the same column. Here is the sample file.. ashop0004 SQL- 06/14/2009 06/14/2009 00:04:28 SUM ashop0004 SQL- 06/14/2009 06/14/2009 00:00:37 ... (22 Replies)
Discussion started by: cutechaps
22 Replies
Login or Register to Ask a Question