Inverted commas replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inverted commas replace
# 1  
Old 04-11-2013
Inverted commas replace

Hi,

My input file is like this

Code:
chr1 + "NM_1234"
chr1 - "NM_1234"

If I want my third column to contain both the first and second column values, how do I do it?

I know how to do it by including the column numbers, but I want the values before the inverted commas.

So, my output would be

Code:
chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"

Thanks
# 2  
Old 04-11-2013
Code:
awk '{sub(/"$/,"_"$1"_"$2"\"",$3)}1' file

This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-11-2013
For your input:
Code:
awk '{sub(/"$/,"_"$1"_"$2"&",$3)}1' file

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 04-11-2013
Code:
$ sed -r 's/(.*) (.*) "(.*)"/\1 \2 "\3_\1_\2"/' input
chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"

This User Gave Thanks to hanson44 For This Post:
# 5  
Old 04-12-2013
Alternate Sed..
Code:
$ sed 's/\([^ ]*\) \([^ ]*\) \(.*\).$/\1 \2 \3_\1_\2"/' inputFile
chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"
$

This User Gave Thanks to michaelrozar17 For This Post:
# 6  
Old 04-12-2013
This should work whether the last field contains double quotes or not:
Code:
 
awk '{sub(/[^"]+/,"&_" $1 "_" $2,$NF)}1' file

These 2 Users Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HELP with AWK or SED. Need to replace the commas between double quotes in CSV file

Hello experts, I need to validate a csv file which contains data like this: Sample.csv "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 I just need to check if all the records contain exactly the number of... (5 Replies)
Discussion started by: shell_boy23
5 Replies

2. Shell Programming and Scripting

Replace commas with newlines

Good afternoon, I am trying to read user input. Here is what I have so far: echo "Type the Container ID for every container that you want subnets exported" echo "for (with comma between each one, for example... 1,45,98)" echo -n "if you want every one listed, then just type ALL in caps... (2 Replies)
Discussion started by: brianjb
2 Replies

3. Shell Programming and Scripting

Insert Inverted Commas Around Numeric Values

Hi, I am trying to insert Inverted Commas around all the numeric values within a comma seperated string / variable. 1111,2222,3333,4444 I would like it to be: '1111','2222','3333','4444' Note - This string could have a differing amount of numeric values each time the variable is... (4 Replies)
Discussion started by: RichZR
4 Replies

4. Shell Programming and Scripting

Replace field with commas with field without commas

Hey guys, I have the following text: 1,2,3,4,5,6,'NULL','when',NULL,1,2,0,'NULL' 1,2,3,4,5,6,'NULL','what','NULL',1,2,0,1 I need the same text with the word NULL without commas u know something like this: 1,2,3,4,5,6,NULL,'when',NULL,1,2,0,NULL 1,2,3,4,5,6,NULL,'what','NULL',1,2,0,1 ... (1 Reply)
Discussion started by: lmyk72
1 Replies

5. Shell Programming and Scripting

replace but skip data between certain commas

OK, I am one needy dude. However, how can I make the program NOT change any of the values BETWEEN the first and second "," ? I dont want any of the numbers changed that are preceded by "AT". I want ALL other numeric values > 300 changed to 300. cat qin.csv |head... (4 Replies)
Discussion started by: herot
4 Replies

6. Red Hat

Sometimes my xterm colors get inverted

I don't know exactly when or why, maybe running less or some command, my white text on a black background gets inverted and all the text looks like it is "selected", it is white background with black text. it is very annoying. I found this solution.;. export TERM=vt100 vi This... (0 Replies)
Discussion started by: srhadden
0 Replies

7. Shell Programming and Scripting

parsing log files, removing spaces and replace with commas

Hello all i am working on a database to import log files from my systems, but i cannot seem to find the answer. I searched here for a good bit and couldnt peice together what i was looking for. I know you could do this with awk, i just dont know how. Any help would be greatly appreciated.... (6 Replies)
Discussion started by: caddyjoe77
6 Replies

8. Shell Programming and Scripting

replace one or more tabs with commas

Hi, Can any one tell me how to replace one or more tabs from start of the line and in between the words with commas in the file using unix commands? My actual data in the text file is as below with spaces.The spaces are not being shown in the post..please see them while replying to the post.... (1 Reply)
Discussion started by: tucs_123
1 Replies

9. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies

10. Shell Programming and Scripting

difference between double inverted coma and single inverted comma

Whats the basic difference between double inverted comma and single inverted comma and no comma applied at all? Eg1 if Eg2 if iEg3 f (1 Reply)
Discussion started by: abhisekh_ban
1 Replies
Login or Register to Ask a Question