The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
word wrap issue with grep bowtiextreme HP-UX 4 04-30-2008 07:39 PM
Unix Arithmatic operation issue , datatype issue thambi Shell Programming and Scripting 23 02-19-2008 07:19 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM
recursive grep issue Mace UNIX for Dummies Questions & Answers 1 08-11-2006 07:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2008
soujanya_srk soujanya_srk is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 14
issue with grep

using grep, i have a file emp.lst, and i want all those records
where "S" or "s" (capital or small) is not there

i used this

grep [^S] emp.lst

when i use grep [S] emp.lst

i am getting rows with S..but why negate (^) is not working?
  #2 (permalink)  
Old 01-04-2008
theninja theninja is offline
Registered User
  
 

Join Date: Jan 2008
Location: St. Louis
Posts: 50
I'm not exactly sure what you want out of the output, but try this

grep -vi s emp.lst

This will return everything without a S or s in the line.
  #3 (permalink)  
Old 01-04-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
^ is not negate

to get everything but, use the -v as previous post

the ^ is a special location character, similar to the $
the ^ locks to the beginning of text and the $ locks to end

sample.txt contains
begin this
more and more
then end

> grep "^begin" sample.txt
begin this
> grep "end$" sample.txt
then end
  #4 (permalink)  
Old 01-04-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 707
Hi.

I think the invert, "-v", option is easiest to use. The "^", normally used as a beginning-of-line-anchor, takes on a special meaning when used in the character class notation, "[string_of_characters]", to mean "not these characters": "[^not_these]".

So you could use either method, the "-v", or the "[^]", but if you use a character class, you would need to set up the regular expression so that it would match every character on a line:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate expressions that match omitted characters.

set -o nounset
echo

debug=":"
debug="echo"

## The shebang using "env" line is designed for portability. For
#  higher security, use:
#
#  #!/bin/sh -

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash

echo

FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from grep:"
grep -vi "s" $FILE

echo
echo " Results from more complicated expression:"
grep '^[^sS]*$' $FILE

exit 0
Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0

 Input file data1:
Line number one.
a
s
S
Line that shuld match character at end: s
S beginning on a line.
Line with s and S in the middle.
Line omitting the character for which we look.
Last line.

 Results from grep:
Line number one.
a
Line omitting the character for which we look.

 Results from more complicated expression:
Line number one.
a
Line omitting the character for which we look.
The use of regular expressions often takes lots of practice to use (and appreciate) ... cheers, drl
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0