to add new column for all reocrds in a file in KSH please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to add new column for all reocrds in a file in KSH please
# 1  
Old 11-06-2005
Lightbulb to add new column for all reocrds in a file in KSH please

i want to add a new column at the end for all the reocrds in a
file

for ex:

file name is abc.wlg.x.y.z
records like
1,2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8
2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,k
3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,k,l
4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,u,i,o
1,2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,i,u

i want to add xyz for all the records into file abc.wlg.x.y.z
and output like
1,2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,xyz
2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,k,xyz
3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,k,l,xyz
4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,u,8,u,i,o,xyz
1,2,3,4,5,6,8,y,u,8,1,2,3,4,5,6,8,y,i,u,xyz

Last edited by pulse2india; 11-06-2005 at 12:36 AM..
# 2  
Old 11-06-2005
Try this:
sed 's/$/,xyz/' < inputfile > outputfile
# 3  
Old 11-06-2005
If you want an in place substitution:

perl -p -i -e 's/$/,xyz/g' file_name

Just a substituted output:

sed 's/$/,xyz/g' file_name
# 4  
Old 11-06-2005
to add columns to all the records in a file

thanks for input...
i want to change like i have to add 'xyz' in 18th position and its a comma delimeted one.
Thanks in advance
# 5  
Old 11-06-2005
Code:
nawk ' 
  BEGIN {
     FS=OFS=","
  }
  { $17=$17 FS "xyz" }
  1' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Add new column from another file

Hi, I have 2 files. file1 contains by lines: hash:salt:id file2 contains by lines: username:hash:salt I would like to add a new coloumn (id) form file1 to file2. The new file should contains: username:hash:salt:id Note: file1 contains less rows than file2. I tried paste -d':' file1... (12 Replies)
Discussion started by: freeroute
12 Replies

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

KSH Script to Execute command from specific column in file

Hi Unix Experts,Team I have a file (say comand_file.prm), The file has a command specified in column 6 (say "./execute_script.sh"). I want to execute this command in my script. I am writing a KSH script to achieve this. Could you please assist me with this. (6 Replies)
Discussion started by: Jeevanm
6 Replies

7. 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

8. 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

9. Shell Programming and Scripting

Finding unique reocrds at a particular field

I have a pipe delimited flat file. I want to grep the records that are unique in the 4th field and repeat only once in the file for e.g.. if the file contains this 3 records i want to get the o/p as: I just gave a sample here and the file is huge one and i cant just grep from the... (7 Replies)
Discussion started by: dsravan
7 Replies

10. Shell Programming and Scripting

pulling a column from a file in ksh

I would like to pull a column from a file and place it in a variable: The file would look like this: N.Korea gibberish garbage S.Korea gibberish garbage USA gibberish garbage Iraq gibberish garbage Canada gibberish garbage and items in the first... (8 Replies)
Discussion started by: dangral
8 Replies
Login or Register to Ask a Question