0

I've read here that I can replace the values of all columns containing a particular text using

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

But where do I tell awk the name of the file I want to perform this operation on? And instead of searching for the literal "CC", how can search for a column matching the pattern A{7}?

  • 1
    Filename would be the last argument! – devnull Mar 13 '14 at 16:24
  • awk is like most Unix commands: it reads from files named on the command line, or from stdin if no filenames are given. – Barmar Mar 15 '14 at 9:44
0

Test file:

A       CC      _AAAAAAA_       foo
C       AA      _AAAAAAA_       foo

awk -F'\t' -vOFS='\t' '{ gsub("CC", "C", $1) ; gsub("AA", "A", $1) ; print; '\
'for (i=1; i<=NF; i++) if ($i ~ /A{7}/) print "   $" i ": " $i;}' file
A       CC      _AAAAAAA_       foo
   $3: _AAAAAAA_
C       AA      _AAAAAAA_       foo
   $3: _AAAAAAA_

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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