Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • The second column is not "1" exactly, I just use 1 to represent the data, the exact data is "CD127", I replace "1" to CD127 in the command you gave but did not work Commented May 28, 2019 at 20:31
  • And my input file actually not tab separate it's separate by "," and I updated the file format at this answer. Commented May 28, 2019 at 20:59
  • 1
    @WendyHuang With the field separator changed and quotes, try awk -F, 'BEGIN{OFS=","} $2 == "CD1" { print $2, $1, $3 }' inputfile. I'm an awk noob, but it seems to do the job. Commented May 28, 2019 at 21:38
  • @Freddy I tried your command, it did extract the row that second column is "CD1" but it didn't print out the third column in the result. Commented May 29, 2019 at 0:43
  • @WendyHuang Hmm, I can't reproduce it. Any difference if you use awk 'BEGIN{FS=","; OFS=","} $2 == "CD1" { print $2, $1, $3 }' inputfile? This is the same command, just different syntax. And if you remove $2 == "CD1" it should just swap column one and two of your data. If that doesn't help we'll have to wait for an expert... Commented May 29, 2019 at 1:13