Grep to return lines not containing a character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep to return lines not containing a character
# 1  
Old 12-04-2011
Grep to return lines not containing a character

Hello , this is my first topic cause I need your little helpSmilie

I got .txt file, and I want to find lines without letter 'a', so im writing:

grep "[^a]" list.txt (list.txt is the file of course)
and i have no idea why it's not working because it shows lines with a.
# 2  
Old 12-04-2011
Hello, and welcome.

You're grepping for "not a", which means any lines containing something that is not an a will be returned. Lines which contain only one or more a's will not be returned.

Code:
$ cat file
a
b
c
dad
aa
f

$ grep "[^a]" file
b
c
dad
f

Try using grep -v a file instead.
This User Gave Thanks to Scott For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File

Hi All It's me again with another huge txt files. :confused: What I have: - I have 33 huge txt files in a folder. - I have thousands of line in this txt file which contain many the letter "x" in them. - Some of them have more than one "x" character in the line. What I want to achieve:... (8 Replies)
Discussion started by: Nexeu
8 Replies

2. Shell Programming and Scripting

Grep command to return all the lines between one matched pattern to another.

14:15:00- abcdefghijkl. 14:30:00- abcdefghijkl. 14:35:00- abcdefghijkl. 123456789. 123456789. 14:45:00- abcdefghijkl. 14:50:00- abcdefghijkl. 123456789. 15:30:00-abcdefghijkl. (3 Replies)
Discussion started by: dev_shivv
3 Replies

3. Solaris

Grep command to return all the lines from one matched pattern to another.

For example a log file looks like below- 13:30:00- abcdefghijklhjghjghjhskj. abcdefghijkl. 14:15:00- abcdefghijkl. 14:30:00- abcdefghijkl. 14:35:00- abcdefghijkl. 123456789. 123456789. 14:45:00- abcdefghijkl. (0 Replies)
Discussion started by: dev_shivv
0 Replies

4. Shell Programming and Scripting

Return part of string after X numbers of a character

My input strings look something like this: /dev/vs/dsk/group/vol I want to print just "group" out of the line... which is always found between the 4th and 5th "/" in the string. I figure I have to use awk, sed, or some combination to do this, but I've searched the forums and can't find... (2 Replies)
Discussion started by: ltricarico
2 Replies

5. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

6. Shell Programming and Scripting

How to grep all lines from a file NOT having a certain character

Hi, I have for instance following INPUT file from which I want to grep ALL lines NOT containing the literal '{' into an OUTPUT file: ... RUNJOB=1,AxBxALLxGEx RUNJOB=0,AxBxDELxGExPRAEMxABLxZGS RUNJOB=0,AxBxDELxGExPRAEMxHARM RUNJOB=0,{UNIX: echo '§ASG§;%ASG_START}... (8 Replies)
Discussion started by: ABE2202
8 Replies

7. Shell Programming and Scripting

sed and character return problem

Hi, I have a problem with sed. It doesn't recognize the "\n" character. It substitudes an "n", instead of introducing a new line. This doesn't happend with print $ print "test \n \n" (it deos introduce two lines after hello) (AIX) $ sed s/bc/\n/g test.1 >test.2 $ cat test.1 bcdefg... (3 Replies)
Discussion started by: Santiago
3 Replies

8. UNIX for Dummies Questions & Answers

grep for a line then return lines above

Hey guys, I just want to grep for a line then return a few lines above it I can't seem to find what im looking for on google can someone help me out? This is on Solaris 9..... I don't have GNU grep so -B and -A commands will not work (3 Replies)
Discussion started by: kingdbag
3 Replies

9. Shell Programming and Scripting

Substituting carriage return followed by newline character - HELP

-------------------------------------------------------------------------------- Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the... (14 Replies)
Discussion started by: djkane
14 Replies

10. Shell Programming and Scripting

Test return character.

Hi, in my korn shell I have this code: typeset -uL1 rc read rc?"Insert Y=Yes (default) or N=No >>" If I press enter without value I wish to set rc=Y. This is my default. This test: if ] then .... Do not work. I hope in your help. Thanks in advance. Regards, Giovanni (3 Replies)
Discussion started by: gio123bg
3 Replies
Login or Register to Ask a Question