Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to replace "CC" with "C" and "AA" with A" in a particular column of Tab delimited file (using awk probably).

share|improve this question
add comment

1 Answer

awk -F'\t' -vOFS='\t' '{ gsub("CC", "C", $1) ; gsub("AA", "A", $1) ; print }'

Replace $1 with the column that you wish to modify.

share|improve this answer
 
In case the delimiter has to be kept, a -vOFS='\t' option may be added. –  manatwork Jun 14 '12 at 10:18
 
@manatwork Good point, added. –  Chris Down Jun 14 '12 at 10:20
 
fantastic! works as per usual!!! –  alex Jun 14 '12 at 10:51
 
Some versions of awk don't have a gsub function. How would you do it then? Can sed be used instead? –  rahmu Jun 14 '12 at 13:33
 
@rahmu - gsub() has been defined by POSIX for over 20 years, so my suggestion would be to get a version of awk that isn't downright awful ;-) –  Chris Down Jun 14 '12 at 13:40
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.