-1

I want to pull all rows from a text file in linux which contain a specific number (in this case 9913) in a specific column (column 4). This is a tab-delimited file, so I am calling this a column, though I am not sure it is.

In some cases, there is only one number in column 4, but in other lines there are multiple numbers in this column (ex. 9913; 4444; 5555). I would like to get any rows for which the number 9913 appears in the 4th column (whether or not it is the only number or in a list). How do I put all lines which contain the number 9913 in column 4 and put them in their own file?

Here is an example of what I have tried:

cat file.txt | grep 9913 > newFile.txt

result is a mixture of the following:

CDR1as CDR1as ENST00000003100.8 9913 AAA-GGCAGCAAGGGACUAAAA (files that I want)

CDR1as CDR1as ENST00000399139.1 9606 GUCCCCA................(file ex. I don't want)

I do not get any results when calling a specific column. Shown by the helper below, the code is not recognizing the columns I think, and I get blank files when using awk.

awk '$4 == "9913"' file.txt > newfile.txt

will give me no transfer of data to a new file.

Thanks

ngross13
  • 1
  • 1

1 Answers1

0

This is one way of doing it

awk '$4 == "9913" {print $0}' file.txt > newfile.txt

or just

awk '$4 == "9913"' file.txt > newfile.txt
usha
  • 28,973
  • 5
  • 72
  • 93
  • note that `{print $0}` is superfluous here, since it is `awk`'s default behaviour. So `awk '$4 == "9913"' file` suffices. – fedorqui Nov 04 '16 at 15:17
  • Thank you. I just edited above. For some reason this is not working for my data, although I have seen it in other posts as well. I am not getting any lines transferred to the new file when I use awk – ngross13 Nov 05 '16 at 17:01