Grep -v command


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Grep -v command
# 1  
Old 09-12-2019
Grep -v command

Hi,


I have a file like this:
Code:
[chr10    165453    165506    NB551726:5:H2HT5BGXC:2:21303:24622:7645    1    -
chr10    166943    166996    NB551726:5:H2HT5BGXC:1:21204:26106:6737    0    -
chr10    190746    190799    NB551726:5:H2HT5BGXC:4:21407:6393:8844    0    -
chr10    198550    198601    NB551726:5:H2HT5BGXC:2:12103:20108:8195    0    -]


and I am using grep -v to remove both 0 and 1 at the same time, but it is not working.
How to remove the entries in the file which have 0 and 1 and retain the others.
Can someone help.
# 2  
Old 09-12-2019
Please give an example of what your output should look like. Because the file as listed has 0s and 1s on all lines, and therefore grep as you propose to use it will delete all lines,


Andrew
This User Gave Thanks to apmcd47 For This Post:
# 3  
Old 09-12-2019
Code:
chr10    85261    85334    NB551726:5:H2HT5BGXC:1:12302:10118:15866    1    +
chr10    86743    86797    NB551726:5:H2HT5BGXC:4:23505:9965:12318    1    -
chr10    152763    152818    NB551726:5:H2HT5BGXC:1:11101:11832:4136    21    +
chr10    165453    165506    NB551726:5:H2HT5BGXC:2:21303:24622:7645    1    -
chr10    166943    166996    NB551726:5:H2HT5BGXC:1:21204:26106:6737    0    -
chr10    190746    190799    NB551726:5:H2HT5BGXC:4:21407:6393:8844    0    -
chr10    198550    198601    NB551726:5:H2HT5BGXC:2:12103:20108:8195    0    -
chr10    198859    198912    NB551726:5:H2HT5BGXC:2:23106:23104:16217    1    -
chr10    253095    253145    NB551726:5:H2HT5BGXC:1:12208:13468:12307    1    -
chr10    253673    253726    NB551726:5:H2HT5BGXC:1:21105:3541:19675    1    +
chr10    270718    270779    NB551726:5:H2HT5BGXC:1:21302:6151:20084    36    +
chr10    279976    280049    NB551726:5:H2HT5BGXC:2:13202:7290:18772    42    +
chr10    283222    283281    NB551726:5:H2HT5BGXC:1:11101:10679:13185    22    +
chr10    295639    295667    NB551726:5:H2HT5BGXC:2:23312:6151:17914    22    +
chr10    299560    299613    NB551726:5:H2HT5BGXC:1:23201:2570:5802    36    +
chr10    305259    305319    NB551726:5:H2HT5BGXC:1:11108:11822:9076    36    +
chr10    312027    312074    NB551726:5:H2HT5BGXC:2:12205:3503:10905    1    +
chr10    326693    326754    NB551726:5:H2HT5BGXC:3:12409:12174:3620    36    +
chr10    333356    333417    NB551726:5:H2HT5BGXC:3:11612:14865:1631    36    +
chr10    342529    342583    NB551726:5:H2HT5BGXC:1:11103:5762:7412    1    +
chr10    379970    380025    NB551726:5:H2HT5BGXC:2:23309:24673:10995    1    -
chr10    390585    390649    NB551726:5:H2HT5BGXC:2:21201:17184:1970    41    -
chr10    403073    403135    NB551726:5:H2HT5BGXC:4:22411:12518:10842    36    +
chr10    434880    434942    NB551726:5:H2HT5BGXC:1:11104:1268:15557    21    +
chr10    483038    483100    NB551726:5:H2HT5BGXC:2:22311:25390:20113    11    +
chr10    503546    503580    NB551726:5:H2HT5BGXC:4:13503:22757:1800    22    +
chr10    508971    509024    NB551726:5:H2HT5BGXC:2:21311:2213:13019    1    +
chr10    523026    523082    NB551726:5:H2HT5BGXC:3:12610:14716:4694    44    -
chr10    556875    556935    NB551726:5:H2HT5BGXC:3:11402:15158:12217    36    +
chr10    572659    572731    NB551726:5:H2HT5BGXC:3:23406:8429:3838    42    +
chr10    632605    632666    NB551726:5:H2HT5BGXC:4:21501:15836:16570    36    +
chr10    654420    654525    NB551726:5:H2HT5BGXC:3:11511:18064:17880    0    -
chr10    695526    695596    NB551726:5:H2HT5BGXC:1:13301:7447:12370    42    -
chr10    703974    704036    NB551726:5:H2HT5BGXC:2:11306:16949:4387    12    -
chr10    745719    745782    NB551726:5:H2HT5BGXC:4:22510:13285:17813    41    +
 chr10    777527    777553    NB551726:5:H2HT5BGXC:1:12206:12418:9864    0    +

and the output should have all the other entries except the lines having 0 and 1 in the 5th column.

Last edited by Scrutinizer; 09-14-2019 at 05:53 AM.. Reason: Removed quote tags
# 4  
Old 09-12-2019
Try
Code:
grep -v " [01] *[+-]" file

This User Gave Thanks to RudiC For This Post:
# 5  
Old 09-13-2019
doesnt work
# 6  
Old 09-13-2019
Hi,

Can you post the output to show how it doesn't work, that would be more helpfull.

Regards

Gull04
These 2 Users Gave Thanks to gull04 For This Post:
# 7  
Old 09-13-2019
Quote:
Originally Posted by Amit Pande
doesnt work
Does:
Code:
grep -v " [01] *[+-]" file
chr10    152763    152818    NB551726:5:H2HT5BGXC:1:11101:11832:4136    21    +
chr10    270718    270779    NB551726:5:H2HT5BGXC:1:21302:6151:20084    36    +
chr10    279976    280049    NB551726:5:H2HT5BGXC:2:13202:7290:18772    42    +
chr10    283222    283281    NB551726:5:H2HT5BGXC:1:11101:10679:13185    22    +
chr10    295639    295667    NB551726:5:H2HT5BGXC:2:23312:6151:17914    22    +
chr10    299560    299613    NB551726:5:H2HT5BGXC:1:23201:2570:5802    36    +
chr10    305259    305319    NB551726:5:H2HT5BGXC:1:11108:11822:9076    36    +
chr10    326693    326754    NB551726:5:H2HT5BGXC:3:12409:12174:3620    36    +
chr10    333356    333417    NB551726:5:H2HT5BGXC:3:11612:14865:1631    36    +
chr10    390585    390649    NB551726:5:H2HT5BGXC:2:21201:17184:1970    41    -
chr10    403073    403135    NB551726:5:H2HT5BGXC:4:22411:12518:10842    36    +
chr10    434880    434942    NB551726:5:H2HT5BGXC:1:11104:1268:15557    21    +
chr10    483038    483100    NB551726:5:H2HT5BGXC:2:22311:25390:20113    11    +
chr10    503546    503580    NB551726:5:H2HT5BGXC:4:13503:22757:1800    22    +
chr10    523026    523082    NB551726:5:H2HT5BGXC:3:12610:14716:4694    44    -
chr10    556875    556935    NB551726:5:H2HT5BGXC:3:11402:15158:12217    36    +
chr10    572659    572731    NB551726:5:H2HT5BGXC:3:23406:8429:3838    42    +
chr10    632605    632666    NB551726:5:H2HT5BGXC:4:21501:15836:16570    36    +
chr10    695526    695596    NB551726:5:H2HT5BGXC:1:13301:7447:12370    42    -
chr10    703974    704036    NB551726:5:H2HT5BGXC:2:11306:16949:4387    12    -
chr10    745719    745782    NB551726:5:H2HT5BGXC:4:22510:13285:17813    41    +

These 2 Users Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help on grep command

for example i have a directory home/solaris/unix/samplefiles/ with defaults files in it.. those default files have 1 word in common "UNIX". how can i list the files without "UNIX" words in it using grep command thanks, im using unix solaris, korn shell.. (1 Reply)
Discussion started by: daveaztig14
1 Replies

2. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

3. Shell Programming and Scripting

Grep command

grep -i -f panel_genes.txt hg19_refGene.txt > match.txt seems to be pulling names the do not exist in the input file (panel_genes.txt) - the output is attached as well (match.txt) For example, RNF185 or ZNF146 are not genes in the input. I am trying to match the input file genes only and am... (9 Replies)
Discussion started by: cmccabe
9 Replies

4. Shell Programming and Scripting

help on grep command...

Hi I have lots of file in on folder and i want to egrep from only few files. List of files...... Polt_KJ_430_OutputRBS_istUt_CR2.log Polt_KN_4122_OutputRBS_ncChk_CR.log Polt_LN_2230_OutputRNC_Hth_CLKLKL.log Solt_KJ_430_OutputRBS_istUt_CR2.log Solt_KN_4122_OutputRBS_ncChk_CR3.log... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

Grep Command

Hi, I have around 500 Text files and Each file will be having either String1 or String2. I want to list the file only which has String1 and Sting2 in a single command.. (5 Replies)
Discussion started by: balasubramani04
5 Replies

6. Shell Programming and Scripting

Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while I've been trying to do: cp... (6 Replies)
Discussion started by: Critical jeff
6 Replies

7. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

8. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies

9. UNIX for Dummies Questions & Answers

grep command

hi all i have directory /usr under this directory i have subdirectories tmp1,tmp2,tmp3 like this /usr/tmp1 /usr/tmp2 /usr/tmp3 and so on i want to search string in files (i don't know the name of the files)and i want to serch it in all the directories under the /usr how shell i do... (3 Replies)
Discussion started by: naamas03
3 Replies

10. Shell Programming and Scripting

grep command

What is the meaning of this grep -v $object grant_BU.sql>temp (1 Reply)
Discussion started by: debasis.mishra
1 Replies
Login or Register to Ask a Question