How can i substitute a header column?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can i substitute a header column?
# 1  
Old 05-17-2013
How can i substitute a header column?

Hi,

I have a txt file with multiple columns and i want to substitute the header of the first column.
Example:

Code:
Seq. Name  Seq. Length #Hits min. eValue mean Similarity #GOs GOs Enzyme Codes InterProScan
comp1000201_c0_seq1   ---NA--- 337 0   0 -   
comp1000297_c0_seq1   ---NA--- 612 0   0 -   
comp100036_c0_seq1   ---NA--- 333 0   0 -   
comp10003_c1_seq1   ---NA--- 328 0   0 -


I want to substitue Seq. Name by transcript_id without touching anything else.

How can i do that in the cluster?
Thanks,

Last edited by Scott; 05-17-2013 at 05:07 PM.. Reason: Code tags
# 2  
Old 05-17-2013
Hi,

You can use below method using 'sed':


sed '1s/Seq. Name/transcript_id/' <filename>


Since we are not substituting globally using "g", this would only replace the first occurence of the string, which is your header.
Hope this helps.

Thanks,
Vijay
# 3  
Old 05-17-2013
Code:
$ awk 'NR==1{$1="transcript_id"}1' file

# 4  
Old 05-21-2013
Hi all,

It worked, thanks. But now i realized that even the whole .txt file is tab delimited the first row is space delimited and this is causing me a lot of problems.
Is there any way to change the whole first row to be tab delimited instead of space delimited?

Thanks.
# 5  
Old 05-22-2013
Thanks RudiC,

What about if i want to change the header of the 2nd and the 3rd columns?

Thanks again.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies

2. UNIX for Dummies Questions & Answers

Substitute first column based on second column

Hi, I have files with lines that look like HSQ1008:141:D0CC8ACXX:3:1106:17255:124378 163 chr14 I'm wondering how I can output a file that appends /1 if the second column is 99 or 83 and a /2 if the second column is 163 or 147. Also I want to put \n + \n between each the second... (1 Reply)
Discussion started by: jyu429
1 Replies

3. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

4. Shell Programming and Scripting

awk to substitute third column if first column is greater than interest

A file 2400 2800 PSC000289 3200 3896 PCS000289 3333 3666 PCS000221 222 1000 PCS000222 3299 3600 PSC000289 Question is while if third column is PCS000289 and first column should be greater than 3000, then replace PCS000289 by YES, remaining the others column same. ... (1 Reply)
Discussion started by: cdfd123
1 Replies

5. Shell Programming and Scripting

substitute in first column

Hi, I have a file which has multiple columns in and i want to replace first column with : in between them. input_file 21000012343456 asdf 21000012343478 asd3 21000012343423 asdf 21000012343445 asdf 21000012343489 asdf output file 21:00:00:12:34:34:56 asdf 21:00:00:12:34:34:78 asd3... (6 Replies)
Discussion started by: jpkumar10
6 Replies

6. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

7. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

8. Shell Programming and Scripting

using awk to substitute data in a column delimited text file

using awk to substitute data in a column delimited text file hello i would like to use awk to do the following calculation from the following snippet. input file C;2390 ;CV BOUILLOTTE 2L 2FACES NERVUREES ;1.00 ;3552612239004;13417 ;25 ;50 ; 12;50000 ; ; ... (3 Replies)
Discussion started by: iindie
3 Replies

9. Shell Programming and Scripting

Column header

Hello all, We are trying to run a script in Oracle DB from AIX. We need to set the Column Header while executing the query to generate the Output. For eg. select city, name from emp; It need to generate report in .csv format as CITY NAME atla tom cincin jack How I... (1 Reply)
Discussion started by: velappangs
1 Replies

10. Shell Programming and Scripting

awk/sed column replace using column header - help

$ cat log.txt Name Age Sex Lcation nfld alias xsd CC 25 M XYZ asx KK Y BB 21 F XAS awe SS N SD 21 M AQW rty SD A How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column? so that the final output will become: Name Age Sex... (10 Replies)
Discussion started by: jkl_jkl
10 Replies
Login or Register to Ask a Question