Add specific text to columns in file by sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add specific text to columns in file by sed
# 1  
Old 03-30-2015
Add specific text to columns in file by sed

What is the proper syntax to add specific text to a column in a file? Both the input and output below are tab-delineated. What if there are multiple text/fields, such as /CP&/2 /CM&/3 /AA&/4 Thank you Smilie.

Code:
 sed 's/[^\\t]*/Index&/1' del.txt.hg19_multianno.txt > matrix.del.txt

# 2  
Old 03-31-2015
Could you please provide sample input and expected output?
# 3  
Old 03-31-2015
In the attached .zip the text file is the input and the .xls is the desired output.
The green highlight comes from the text fie and will have S1 - AP1 as row headers. It will also have data in those columns ... A1 - R1 (headers only) and AQ1-AX1 (headers only). No data is needed for those columns (only the headers). I have a SQL import that is expecting all those columns in one file.


Code:
Index Chromosome ... Amino Acid Change Chr Start ... clinvarsubmit clinvarreference HP SPLICE ... Sanger References

So, the text in bold is added to the text file and a new file with the combined is saved in the path. Thank you
# 4  
Old 03-31-2015
Quote:
Originally Posted by cmccabe
In the attached .zip the text file is the input and the .xls is the desired output.
The green highlight comes from the text fie and will have S1 - AP1 as row headers. It will also have data in those columns ... A1 - R1 (headers only) and AQ1-AX1 (headers only). No data is needed for those columns (only the headers). I have a SQL import that is expecting all those columns in one file.


Code:
Index Chromosome ... Amino Acid Change Chr Start ... clinvarsubmit clinvarreference HP SPLICE ... Sanger References

So, the text in bold is added to the text file and a new file with the combined is saved in the path. Thank you
This is the same problem that you asked in your other thread:

Perl command in bash

where you had posted a Perl program to solve this problem.

Why two threads with different programs (Perl and sed) for the same problem?
# 5  
Old 03-31-2015
I was just curious as to how sed would handle this. I am just trying to learn shell scripting as it is very useful in the sciences. Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add character to specific columns using sed or awk and make it a permanent change

Hi, I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches. file has lot of functions defined a.sh #!/bin/bash fn a { beautiful evening sunny day } fn b { } fn c { hello world .its a beautiful day ... (12 Replies)
Discussion started by: ashima jain
12 Replies

2. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

3. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

4. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

How do you view specific columns from a space delimited text file?

I have a space delimited text file with 1,000,000+ columns? I would only like to view specific ones (let's say through 1:10), how can I do that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

6. Shell Programming and Scripting

remove white space from specific columns in text file

Hello i have a text file like this: 1 AB AC AD EE 2 WE TR YT WW 3 AS UY RF YT the file is bigger , but that's an example of the data what i want to do is to merge all columns together except the first one, it will become like this : 1 ABACADEE 2 WETRYTWW 3 ASUYRFYT (8 Replies)
Discussion started by: shelladdict
8 Replies

7. UNIX for Dummies Questions & Answers

How To Add Text To Specific File?

There is file named .htaccess. It is located in many directories on my web server. Instead of manually editing each file to add specific text, i thought there is possibly a command which will allow me to do that. What i need to be done exactly? In all .htaccess files i need to add/append the... (2 Replies)
Discussion started by: Boris_yo
2 Replies

8. Shell Programming and Scripting

add newline in file after finding specific text

Hi All, I am tring to insert a newline with "/" in a text file whenever there is the text "end;" right now I have inside file: . . end; I want to have: . . end; / I tried doing the following within the file :g/^end;/s//end; \/ / (4 Replies)
Discussion started by: jxh461
4 Replies

9. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

10. Shell Programming and Scripting

Replacing text on specific columns

Hi , i have one file like : APP101A APP103B MSG307A MSG308B XADM002A and so on , and i expect to replace the last character A by B and B by A the result would be : APP101B APP103A MSG307B MSG308A XADM002B how can i do that ? (3 Replies)
Discussion started by: Nicol
3 Replies
Login or Register to Ask a Question