Appending 'string' to file as first column.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending 'string' to file as first column.
# 1  
Old 04-02-2008
Appending 'string' to file as first column.

Hi , I have the below file with 6 columns.I want to append 'File1' as the 1 column to the file. i have the sample code .It is not working . can u please correct this or make new one .....
Code:
awk 'print {'File1',$1,$2,$3,$4,$5,$6}' Source_File> Result_File

Source_File:
Code:
E100,0,5/29/1993,0,E001,E000
E102,0,1/23/1994,0,E001,E003
E104,0,6/4/1994,0,E001,E003
E105,0,7/30/1993,0,E001,E003

Result_File :
Code:
File1,E100,0,5/29/1993,0,E001,E000
File1,E102,0,1/23/1994,0,E001,E003
File1,E104,0,6/4/1994,0,E001,E003
File1,E105,0,7/30/1993,0,E001,E003

Please help me .....

Last edited by satyam_sat; 04-02-2008 at 04:43 AM.. Reason: added code tags
# 2  
Old 04-02-2008
try this:
Code:
awk '{ print "File1,"$0}' Source_File> Result_File

# 3  
Old 04-02-2008
Code:
 awk '{print "File1,"$1,$2,$3,$4,$5,$6}' Source_File> Result_File


Last edited by danmero; 04-02-2008 at 05:15 AM.. Reason: Busted :)
# 4  
Old 04-02-2008
Use SED for the same.

sed 's/^/FILE1,/g' file1 > newfile
# 5  
Old 04-02-2008
Error is coming :

awk '{print "File1,"$1,$2,$3,$4,$5,$6}' Source_File> Result_File
Smilie
The code is useful ....but 'File1' is not appending . I tried many times...empty space is coming .....

,E100,0,5/29/1993,0,E001,E000
,E102,0,1/23/1994,0,E001,E003
,E104,0,6/4/1994,0,E001,E003
,E105,0,7/30/1993,0,E001,E003
# 6  
Old 02-19-2009
Hi,

Try the below command. Hope this should work.

awk '{print "File,",$1,$2,$3}' Source_File | sed 's/ //g' > Result_File

Thanks,
Smilie
# 7  
Old 02-20-2009
Working fine for me...

Code:
$ cat source
E100,0,5/29/1993,0,E001,E000
E102,0,1/23/1994,0,E001,E003
E104,0,6/4/1994,0,E001,E003
E105,0,7/30/1993,0,E001,E003

Code:
$ awk '{print "File1,"$1,$2,$3,$4,$5,$6}' source
File1,E100,0,5/29/1993,0,E001,E000
File1,E102,0,1/23/1994,0,E001,E003
File1,E104,0,6/4/1994,0,E001,E003
File1,E105,0,7/30/1993,0,E001,E003

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Appending a column in xlsx file using Python

Is there a way to append an existing xlsx worksheet to add data from a text file ? I have an excel file for which I need to manipulate the first worksheet based on a text file. I match the text file to the xlsx and write the 'Scores' column in the xlsx sheet and save the workbook. For those ... (43 Replies)
Discussion started by: nans
43 Replies

2. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

3. Shell Programming and Scripting

Appending = in particular column in csv file

Hi, I have a requirement to append = in particular row in csv file. Data in csv is as follow: row1,a,a,a row2,b,b,b row3,c,c,c row4,d,d,d csv should be modified at row3 and no. of columns are not fixed but rows are. output should be as: row1,a,a,a row2,b,b,b row3,=c,=c,=c... (2 Replies)
Discussion started by: Divya1987
2 Replies

4. UNIX for Dummies Questions & Answers

Appending a column of numbers in ascending order to a text file

I have a text file where I want to append a column of numbers in ascending orders. Input: 57 abc 25 def 32 ghi 54 jkl Output:57 abc 57 abc 1 25 def 2 32 ghi 3 54 jkl 4 How do I go about doing that? Thanks! (11 Replies)
Discussion started by: evelibertine
11 Replies

5. UNIX for Dummies Questions & Answers

Appending date value mmdd to first column in file

Hi , I have a file with a running sequence number. I need to append a date value mmdd format on to the first column. for e.g.: The file contains records as 001 abc 002 cde 003 edf 004 fgh 005 hik The output should be 1111001 abc 1111002 cde 1111003 edf 1111004 ... (1 Reply)
Discussion started by: kalyansid
1 Replies

6. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

7. Shell Programming and Scripting

Appending string at the end of the file

Hello, I wanted to append 'XYZ' at the end of the text file. How can i do this? I searched the forums and i am not getting what i want. Any help is highly appreciated. Thanks (2 Replies)
Discussion started by: govindts
2 Replies

8. Shell Programming and Scripting

appending column file

Hi all, I have two files with the same number of lines the first file is a.dat and looks like 0.000 1.000 1.000 2.000 ... the fields are tab separated the second file is b.dat and looks like 1.2347 0.546 2.3564 0.321 ... the fields are tab separated I would like to have a file c.dat... (4 Replies)
Discussion started by: f_o_555
4 Replies

9. Shell Programming and Scripting

Appending a column in one file to the corresponding line in a second

It appears that this has been asked and answered in similar fashions previously, but I am still unsure how to approach this. I have two files containing user information: fileA ttim:/home/ttim:Tiny Tim:632 ppinto:/home/ppinto:Pam Pinto:633 fileB ttim:xkfgjkd*&#^jhdfh... (3 Replies)
Discussion started by: suzannef
3 Replies

10. Shell Programming and Scripting

appending string to text file based on search string

Hi, I need to append string "Hi" to the beginning of the lines containing some specific string. How can I achieve that? Please help. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies
Login or Register to Ask a Question