Question: how to extract/grep lines containing specific word?
0
gravatar for arsilan324
16 months ago by
arsilan32470
arsilan32470 wrote:

Hi all,

I am trying to extract lines containing specific word from tabular file! I am using this command

grep "[Sorghum bicolor]" file.txt

Here [Sorghum bicolor] is the word (desired string) for the line which i want to retain. But this comamnd print everything as it is and doesn't filter. I have used -E and -i as well. Also, I want to do the reverse, print lines without this word. Can you please comment? Thanks in advance

awk sed grep • 1.5k views
ADD COMMENTlink modified 16 months ago by Kevin Blighe45k • written 16 months ago by arsilan32470
1
gravatar for Kevin Blighe
16 months ago by
Kevin Blighe45k
Kevin Blighe45k wrote:

Just do:

grep -w "Sorghum bicolor" file.txt

...and the inverse:

grep -w "Sorghum bicolor" -v file.txt
ADD COMMENTlink written 16 months ago by Kevin Blighe45k

For some reason, the output file is still empty. Can you comment on it? Here is the link to the file

ADD REPLYlink written 16 months ago by arsilan32470

You'll probably need

grep -w "[Sorghum bicolor]" file.txt
ADD REPLYlink written 16 months ago by WouterDeCoster40k
1

Thanks! - some things about your file: the formatting is 'all over the place' and it does not look to be in the proper encoding. It looks like you ported it from Excel or something? I cannot confirm because, perhaps, DropBox has modified something.

Look at the file in VIM and you will see many ^M characters, and also run wc -l on the file an you'll get 0 lines. Ensure that the encoding is correct first. Try functions like dos2unix, etc ( take a look here: https://kb.iu.edu/d/acux ).

ADD REPLYlink modified 12 months ago • written 16 months ago by Kevin Blighe45k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 661 users visited in the last hour