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}?

2
  • 1
    Filename would be the last argument!
    – devnull
    Mar 13, 2014 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, 2014 at 9:44

1 Answer 1

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_

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .