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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to add a header to a tab delimited .txt file?
# 1  
Old 05-21-2013
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:

Code:
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  0.00    0.00    0.00    0.00    ---NA---        612     0                       0
       -               
comp100036_c0_seq1      comp100036_c0   333     179.51  1.00    6.72    6.17    100.00  ---NA---        333     0                       0
       -               
comp10003_c1_seq1       comp10003_c1    328     174.51  0.00    0.00    0.00    0.00    ---NA---        328     0                       0
       -               
comp100041_c0_seq1      comp100041_c0   338     184.51  0.00    0.00    0.00    0.00    ---NA---        338     0                       0
       -               
comp100041_c0_seq2      comp100041_c0   302     148.52  0.00    0.00    0.00    0.00    ---NA---        302     0                       0
       -               
comp100041_c0_seq3      comp100041_c0   339     185.51  0.00    0.00    0.00    0.00    ---NA---        339     0                       0
       -               
comp100051_c0_seq1      comp100051_c0   323     169.51  0.00    0.00    0.00    0.00    pogo transposable element with krab domain-like 323     5       8.05925533998611E-10    55.8%   0       -               
comp1000890_c0_seq1     comp1000890_c0  460     306.51  2.00    7.87    7.23    100.00  ---NA---        460     0                       0
       -               
comp1000928_c0_seq1     comp1000928_c0  317     163.51  0.00    0.00    0.00    0.00    40s ribosomal protein s7        317     5       1.02118911037712E-20    66.6%   4       F:GO:0003735; P:GO:0006412; C:GO:0005840; C:GO:0005622          
comp100114_c0_seq1      comp100114_c0   372     218.51  0.00    0.00    0.00    0.00    ---NA---        372     0                       0
       -               
comp100116_c0_seq1      comp100116_c0   389     235.51  0.00    0.00    0.00    0.00    ---NA---        389     0                       0
       -               
comp1001170_c0_seq1     comp1001170_c0  361     207.51  0.00    0.00    0.00    0.00    ---NA---        361     0                       0
       -               
comp1001188_c0_seq1     comp1001188_c0  446     292.51  0.00    0.00    0.00    0.00    ---NA---        446     0                       0
       -               
comp10013_c0_seq1       comp10013_c0    330     176.51  0.00    0.00    0.00    0.00    ---NA---        330     0                       0
       -               
comp1001469_c0_seq1     comp1001469_c0  359     205.51  0.00    0.00    0.00    0.00    ---NA---        359     0                       0
       -               
comp100157_c1_seq1      comp100157_c1   493     339.50  0.00    0.00    0.00    0.00    ---NA---        493     0                       0
       -               
comp100160_c0_seq1      comp100160_c0   395     241.51  0.00    0.00    0.00    0.00    ---NA---        395     0                       0
       -               
comp1001637_c0_seq1     comp1001637_c0  301     147.52  0.00    0.00    0.00    0.00    ---NA---        301     0                       0
       -

And i want to add a header to each column obtaining something like:

Code:
transcript_id	gene_id	Length	effective_length	expected_count	TPM	FPKM	IsoPct	Seq.Description	Seq.Length	#Hits	min.eValue	mean_Similarity	#GOs	GOs	Enzime_codes	InterProScan
comp1000201_c0_seq1	comp1000201_c0	337	183.51	0	0	0	0	---NA---	337	0			0	-		
comp1000297_c0_seq1	comp1000297_c0	612	458.5	0	0	0	0	---NA---	612	0			0	-		
comp100036_c0_seq1	comp100036_c0	333	179.51	1	6.72	6.17	100	---NA---	333	0			0	-		
comp10003_c1_seq1	comp10003_c1	328	174.51	0	0	0	0	---NA---	328	0			0	-		
comp100041_c0_seq1	comp100041_c0	338	184.51	0	0	0	0	---NA---	338	0			0	-		
comp100041_c0_seq2	comp100041_c0	302	148.52	0	0	0	0	---NA---	302	0			0	-		
comp100041_c0_seq3	comp100041_c0	339	185.51	0	0	0	0	---NA---	339	0			0	-		
comp100051_c0_seq1	comp100051_c0	323	169.51	0	0	0	0	pogo transposable element with krab domain-like	323	5	8.06E-10	55.80%	0	-		
comp1000890_c0_seq1	comp1000890_c0	460	306.51	2	7.87	7.23	100	---NA---	460	0			0	-		
comp1000928_c0_seq1	comp1000928_c0	317	163.51	0	0	0	0	40s ribosomal protein s7	317	5	1.02E-20	66.60%	4	F:GO:0003735; P:GO:0006412; C:GO:0005840; C:GO:0005622		
comp100114_c0_seq1	comp100114_c0	372	218.51	0	0	0	0	---NA---	372	0			0	-		
comp100116_c0_seq1	comp100116_c0	389	235.51	0	0	0	0	---NA---	389	0			0	-		
comp1001170_c0_seq1	comp1001170_c0	361	207.51	0	0	0	0	---NA---	361	0			0	-		
comp1001188_c0_seq1	comp1001188_c0	446	292.51	0	0	0	0	---NA---	446	0			0	-		
comp10013_c0_seq1	comp10013_c0	330	176.51	0	0	0	0	---NA---	330	0			0	-		
comp1001469_c0_seq1	comp1001469_c0	359	205.51	0	0	0	0	---NA---	359	0			0	-		
comp100157_c1_seq1	comp100157_c1	493	339.5	0	0	0	0	---NA---	493	0			0	-		
comp100160_c0_seq1	comp100160_c0	395	241.51	0	0	0	0	---NA---	395	0			0	-		
comp1001637_c0_seq1	comp1001637_c0	301	147.52	0	0	0	0	---NA---	301	0			0	-		
comp100165_c0_seq1	comp100165_c0	3023	2869.5	997	419.11	385.11	100	bifunctional atp-dependent dihydroxyacetone kinase fad-amp lyase -like	3023	5	1.16E-132	78.00%	3	F:GO:0005524; F:GO:0004371; P:GO:0006071		
comp1001689_c0_seq1	comp1001689_c0	381	227.51	0	0	0	0	14-3-3 zeta	381	5	3.16E-46	93.00%	2	C:GO:0044424; F:GO:0005515	-	
comp100169_c0_seq1	comp100169_c0	319	165.51	1	7.29	6.7	100	---NA---	319	0			0	-		
comp10017_c0_seq1	comp10017_c0	361	207.51	0	0	0	0	---NA---	361	0			0	-		
comp1001912_c0_seq1	comp1001912_c0	310	156.52	0	0	0	0	---NA---	310	0			0	-		
comp100197_c0_seq1	comp100197_c0	334	180.51	0	0	0	0	---NA---	334	0			0	-		
comp100203_c0_seq1	comp100203_c0	496	342.5	2	7.04	6.47	100	---NA---	496	0			0	-		
comp100206_c0_seq1	comp100206_c0	444	290.51	0	0	0	0	---NA---	444	0			0	-		
comp100214_c0_seq1	comp100214_c0	322	168.51	0	0	0	0	---NA---	322	0			0	-		
comp1002301_c0_seq1	comp1002301_c0	399	245.51	0	0	0	0	---NA---	399	0			0	-		
comp1002310_c0_seq1	comp1002310_c0	338	184.51	0	0	0	0	---NA---	338	0			0	-		
comp100235_c0_seq1	comp100235_c0	405	251.51	1	4.8	4.41	100	---NA---	405	0			0	-		
comp100237_c0_seq1	comp100237_c0	308	154.52	0	0	0	0	---NA---	308	0			0	-		
comp1002527_c0_seq1	comp1002527_c0	337	183.51	0	0	0	0	---NA---	337	0			0	-

Any suggestion?
Thanks.
# 2  
Old 05-21-2013
Hi alisrpp,

>> i want to add a header to each column obtaining something like:

1. Store the header line to a variable.
Code:
h="transcript_id	gene_id ..... "

2. Add the header to your file:
Code:
printf "1\ni\n$h \n.\n\nw\nq\n"|ed -s file

3. Check the header :
Code:
# head -n 1 file

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

5. Shell Programming and Scripting

[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: 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... (4 Replies)
Discussion started by: paolo.kunder
4 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. 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

9. UNIX for Dummies Questions & Answers

Add a new column to a tab delimited text file

I want to add a new column to a tab delimited text file. It will be the first column and it will just be 1's. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

10. UNIX for Dummies Questions & Answers

Adding EMPTY columns to Tab-delimited txt file

Hi I have a txt file with 4 columns where I need to add 4 empty columns in the middle meaning that I need what is currently column 4 to be column 8 in a new file. The idea is that I have to use the file as input in a program that reads the data in column 1 and 8, so the content of the other... (8 Replies)
Discussion started by: Banni
8 Replies
Login or Register to Ask a Question