Inverted commas replace

Hi,

My input file is like this

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

chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"

Thanks

awk '{sub(/"$/,"_"$1"_"$2"\"",$3)}1' file
1 Like

For your input:

awk '{sub(/"$/,"_"$1"_"$2"&",$3)}1' file
1 Like
$ sed -r 's/(.*) (.*) "(.*)"/\1 \2 "\3_\1_\2"/' input
chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"
1 Like

Alternate Sed..

$ sed 's/\([^ ]*\) \([^ ]*\) \(.*\).$/\1 \2 \3_\1_\2"/' inputFile
chr1 + "NM_1234_chr1_+"
chr1 - "NM_1234_chr1_-"
$
1 Like

This should work whether the last field contains double quotes or not:

 
awk '{sub(/[^"]+/,"&_" $1 "_" $2,$NF)}1' file
2 Likes