![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
|||||
|
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
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. |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|