[Solved] Append an header to a tab delimited file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Append an header to a tab delimited file
# 1  
Old 11-21-2012
[Solved] Append an header to a tab delimited file

Dear All,
I would like to find an automatic way to add a given code which belong to a class at the end of the column , for example this is my input file:

Code:
0610009O20Rik					
V$VMYB_01	310	(+)	1	0.971	v-Myb
V$EVI1_04	782	(-)	0.763	0.834	Evi-1
V$ELK1_02	1966	(-)	1	0.984	Elk-1
V$HAND1E47_01	3483	(-)	1	0.976	Hand1/E47
V$FOXD3_01	3869	(-)	1	0.966	FOXD3
V$FOXD3_01	3873	(-)	0.996	0.992	FOXD3
0610040J01Rik					
V$HNF1_C	273	(+)	0.942	0.855	HNF-1
V$OCT1_Q6	465	(+)	0.893	0.921	Oct-1
V$FOXD3_01	601	(+)	1	0.966	FOXD3
V$USF_Q6	1837	(+)	1	0.971	USF
V$COMP1_01	2435	(+)	0.786	0.817	COMP1
V$E2F_02	2779	(-)	1	1	E2F

and this is what I would like to obtain

Code:
0610009O20Rik						
V$VMYB_01	310	(+)	1	0.971	v-Myb	0610009O20Rik
V$EVI1_04	782	(-)	0.763	0.834	Evi-1	0610009O20Rik
V$ELK1_02	1966	(-)	1	0.984	Elk-1	0610009O20Rik
V$HAND1E47_01	3483	(-)	1	0.976	Hand1/E47	0610009O20Rik
V$FOXD3_01	3869	(-)	1	0.966	FOXD3	0610009O20Rik
V$FOXD3_01	3873	(-)	0.996	0.992	FOXD3	0610009O20Rik
0610040J01Rik						
V$HNF1_C	273	(+)	0.942	0.855	HNF-1	0610040J01Rik
V$OCT1_Q6	465	(+)	0.893	0.921	Oct-1	0610040J01Rik
V$FOXD3_01	601	(+)	1	0.966	FOXD3	0610040J01Rik
V$USF_Q6	1837	(+)	1	0.971	USF	0610040J01Rik
V$COMP1_01	2435	(+)	0.786	0.817	COMP1	0610040J01Rik
V$E2F_02	2779	(-)	1	1	E2F	0610040J01Rik
V$OCT1_Q6	2988	(+)	1	0.916	Oct-1	0610040J01Rik


any suggestion?
Thanks for your help,
Paolo

Last edited by paolo.kunder; 11-21-2012 at 11:47 AM..
# 2  
Old 11-21-2012
Code:
awk 'NR==1 { print ; T=$1; next } $1=="" { print ; getline ; print ; T=$1 ; next } { $(NF+1)=T } 1' inputfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-21-2012
great that's work, but I realized that in my input file I have no empty lines,
for example:
Code:
0610009O20Rik					
V$VMYB_01	310	(+)	1	0.971	v-Myb
V$EVI1_04	782	(-)	0.763	0.834	Evi-1
V$ELK1_02	1966	(-)	1	0.984	Elk-1
V$HAND1E47_01	3483	(-)	1	0.976	Hand1/E47
V$FOXD3_01	3869	(-)	1	0.966	FOXD3
V$FOXD3_01	3873	(-)	0.996	0.992	FOXD3
0610040J01Rik					
V$HNF1_C	273	(+)	0.942	0.855	HNF-1
V$OCT1_Q6	465	(+)	0.893	0.921	Oct-1
V$FOXD3_01	601	(+)	1	0.966	FOXD3
V$USF_Q6	1837	(+)	1	0.971	USF
V$COMP1_01	2435	(+)	0.786	0.817	COMP1
V$E2F_02	2779	(-)	1	1	E2F

# 4  
Old 11-21-2012
Code:
awk 'NF==1 { T=$1 ; print ; next } { $(NF+1)=T } } 1' inputfile

# 5  
Old 11-21-2012
thanks!
paolo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

3. Shell Programming and Scripting

Insert a header record (tab delimited) in multiple files

Hi Forum. I'm struggling to find a solution for the following issue. I have multiple files a1.txt, a2.txt, a3.txt, etc. and I would like to insert a tab-delimited header record at the beginning of each of the files. This is my code so far but it's not working as expected. for i in... (2 Replies)
Discussion started by: pchang
2 Replies

4. UNIX for Dummies Questions & Answers

How to add a header to a tab delimited .txt file?

Hi, I have a tab delimited document with 18 columns. My file looks like: comp1000201_c0_seq1 comp1000201_c0 337 183.51 0.00 0.00 0.00 0.00 ---NA--- 337 0 0 - comp1000297_c0_seq1 comp1000297_c0 612 458.50 ... (1 Reply)
Discussion started by: alisrpp
1 Replies

5. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

6. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

7. UNIX for Dummies Questions & Answers

add (append) a column in a tab delimited file

I have a file having the following entries: test1 test2 test3 11 22 33 22 44 66 99 99 44 --- I want to add a column so that the above file becomes: test1 test2 test3 notest 11 22 33 * 22 44 66 * 99 99 44 * --- Thanks (6 Replies)
Discussion started by: mary271
6 Replies

8. Shell Programming and Scripting

Append output in tab delimited format

hello.. i m scripting in Perl and having issue writing the output in specific format..i read two files and run some commands and write output to one file. i want this to be a 2d table, File one has 48 rows and file two has 48 rows, first i take one id from file one, and go to second file, loop... (2 Replies)
Discussion started by: empyrean
2 Replies

9. UNIX for Dummies Questions & Answers

Delete header row and reformat from tab delimited to fixed width

Hello gurus, I have a file in a tab delimited format and a header row. I need a code to delete the header in the file, and convert the file to a fixed width format, with all the columns aligned. Below is a sample of the file:... (4 Replies)
Discussion started by: chumsky
4 Replies

10. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies
Login or Register to Ask a Question