Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [Solved] Wildcards used in find, ls and grep commands Post 302732041 by vbe on Friday 16th of November 2012 12:07:54 PM
Old 11-16-2012
Quote:
User Commands grep(1)

NAME
grep - search a file for a pattern

SYNOPSIS
/usr/bin/grep [-bchilnsvw] limited-regular-expression
[filename]...

/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvwx] -e pattern_list...
[-f pattern_file]... [file]...

/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvwx]
[-e pattern_list]... -f pattern_file... [file]...

/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvwx] pattern
[file]...
Code:
#demo:
slo4:/export/home/vbe $ grep -?
grep: illegal option -- ?
Usage: grep -hblcnsviw pattern file . . .
slo4:/export/home/vbe $ which grep
/bin/grep
slo4:/export/home/vbe $ /usr/xpg4/bin/grep -?
/usr/xpg4/bin/grep: illegal option -- ?
Usage:  grep [-c|-l|-q] [-bhinsvwx] pattern_list [file ...]
        grep [-c|-l|-q] [-bhinsvwx] [-e pattern_list]... [-f pattern_file]... [file...]
        grep -E [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
        grep -E [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
        grep -F [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
        grep -F [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
slo4:/export/home/vbe $

In order to make use of grep -F you have to use /usr/xpg4/bin/grep, instead of the default grep in /usr/bin. Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep and wildcards

Hi guys, a small problem today, I'm grepping a log file containing lines like this below: Mar 09 16:04:00 blabla Mar 09 16:04:02 blabla Mar 09 16:04:05 blabla Mar 09 16:04:15 blabla Mar 09 16:05:06 blabla Mar 09 16:05:23 blabla Mar 09 16:05:25 blabla ... in this file I'm grepping... (5 Replies)
Discussion started by: Lomic
5 Replies

2. UNIX for Dummies Questions & Answers

find and grep commands

I'm having trouble with the following commands i. count the number of lines which end in a 4 letter word grep '{4\}$' bfile <<seems to print out everything abc abc abcd joe joe john bob bill gregory greg greg gregory the grep command prints out the lines with 4 letter words and the... (3 Replies)
Discussion started by: StrengthThaDon
3 Replies

3. UNIX for Dummies Questions & Answers

help with find & grep commands

Folks; First about find: when i run this: find . -name '*log*' -mtime +10 -print | sed 's+^\./++;s+/.*++' | sort -u i got list of log files but also get a directories (although directory names doesn't have "log" in it). How can i exclude the directory from the output of this find command? ... (2 Replies)
Discussion started by: moe2266
2 Replies

4. Shell Programming and Scripting

Perl - grep issue in filenames with wildcards

Hi I have 2 directories t1 and t2 with some files in it. I have to see whether the files present in t1 is also there in t2 or not. Currently, both the directories contain the same files as shown below: $ABC.TXT def.txt Now, when I run the below script, it tells def.txt is found,... (5 Replies)
Discussion started by: guruprasadpr
5 Replies

5. Homework & Coursework Questions

find grep sed commands homework

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to make as home work several commands with gerp find and sed 2. Relevant commands, code, scripts, algorithms: FIND command -use command find... (8 Replies)
Discussion started by: ViruS89
8 Replies

6. Homework & Coursework Questions

Need help using find or locate with wildcards

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: List all files in ~c12100 directory beginning with "BOZO" that end with either "123" or "456" 2. Relevant... (3 Replies)
Discussion started by: ScarletRavin
3 Replies

7. Shell Programming and Scripting

Grep wildcards

Hi all I want to search for number in file presented with wildcard as shown below. cat file.txt 1405 1623 1415 ....... ....... How to search for the number 141526 for example? If the number exist print "Number 141526 exist" if no, print "The number not exist" Thank you in advance. (3 Replies)
Discussion started by: vasil
3 Replies

8. Shell Programming and Scripting

[Solved] Grep within find command

Platform: AIX 6.1/ksh Question1. I want to grep for the string "CUSTOM_PKMS" in all the files in server except those files with extensions .dbf , .ctl and .dmp I started running the following command but it is taking too long because there are lots of .dbf , .ctl and .dmp files in this... (6 Replies)
Discussion started by: John K
6 Replies

9. Shell Programming and Scripting

Grep multiple patterns that contain wildcards

job_count=`grep -e "The job called .* has finished | The job called .* is running" logfile.txt | wc -l` Any idea how to count those 2 patterns so i have a total count of the finished and running jobs from the log file? If i do either of the patterns its works okay but adding them together... (8 Replies)
Discussion started by: finn
8 Replies

10. UNIX for Dummies Questions & Answers

Find command and use of wildcards

greetings, below is the find command i am using for some filesystem maintenance: find /data/Engine \( -type d -name .snapshot -prune -o -type d -wholename "/data/Engine/*/CAE" \ -prune -o -type d -wholename "/data/Engine/*/CAD" -prune -o -name ".*.case" \)\ -mtime +365 -print0 -fls... (5 Replies)
Discussion started by: crimso
5 Replies
fgrep(1)							   User Commands							  fgrep(1)

NAME
fgrep - search a file for a fixed-character string SYNOPSIS
/usr/bin/fgrep [-bchilnsvx] -e pattern_list [file...] /usr/bin/fgrep [-bchilnsvx] -f file [file...] /usr/bin/fgrep [-bchilnsvx] pattern [file...] /usr/xpg4/bin/fgrep [-bchilnqsvx] -e pattern_list [-f file] [file...] /usr/xpg4/bin/fgrep [-bchilnqsvx] [-e pattern_list] -f file [file...] /usr/xpg4/bin/fgrep [-bchilnqsvx] pattern [file...] DESCRIPTION
The fgrep (fast grep) utility searches files for a character string and prints all lines that contain that string. fgrep is different from grep(1) and from egrep(1) because it searches for a string, instead of searching for a pattern that matches an expression. fgrep uses a fast and compact algorithm. The characters $, *, [, ^, |, (, ), and are interpreted literally by fgrep, that is, fgrep does not recognize full regular expressions as does egrep. These characters have special meaning to the shell. Therefore, to be safe, enclose the entire string within single quotes (a'). If no files are specified, fgrep assumes standard input. Normally, each line that is found is copied to the standard output. The file name is printed before each line that is found if there is more than one input file. OPTIONS
The following options are supported for both /usr/bin/fgrep and /usr/xpg4/bin/fgrep: -b Precedes each line by the block number on which the line was found. This can be useful in locating block numbers by con- text. The first block is 0. -c Prints only a count of the lines that contain the pattern. -e pattern_list Searches for a string in pattern-list. This is useful when the string begins with a -. -f pattern-file Takes the list of patterns from pattern-file. -h Suppresses printing of files when searching multiple files. -i Ignores upper/lower case distinction during comparisons. -l Prints the names of files with matching lines once, separated by new-lines. Does not repeat the names of files when the pattern is found more than once. -n Precedes each line by its line number in the file. The first line is 1. -s Works silently, that is, displays nothing except error messages. This is useful for checking the error status. -v Prints all lines except those that contain the pattern. -x Prints only lines that are matched entirely. /usr/xpg4/bin/fgrep The following options are supported for /usr/xpg4/bin/fgrep only: -q Quiet. Does not write anything to the standard output, regardless of matching lines. Exits with zero status if an input line is selected. OPERANDS
The following operands are supported: file Specifies a path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used. /usr/bin/fgrep pattern Specifies a pattern to be used during the search for input. /usr/xpg4/bin/fgrep pattern Specifies one or more patterns to be used during the search for input. This operand is treated as if it were specified as -e pattern_list. USAGE
See largefile(5) for the description of the behavior of fgrep when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of fgrep: LC_COLLATE, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 If any matches are found 1 If no matches are found 2 For syntax errors or inaccessible files, even if matches were found. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/fgrep +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ /usr/xpg4/bin/fgrep +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
ed(1), egrep(1), grep(1), sed(1), sh(1), attributes(5), environ(5), largefile(5), XPG4(5) NOTES
Ideally, there should be only one grep command, but there is not a single algorithm that spans a wide enough range of space-time tradeoffs. Lines are limited only by the size of the available virtual memory. /usr/xpg4/bin/fgrep The /usr/xpg4/bin/fgrep utility is identical to /usr/xpg4/bin/grep -F (see grep(1)). Portable applications should use /usr/xpg4/bin/grep -F. SunOS 5.11 24 Mar 2006 fgrep(1)
All times are GMT -4. The time now is 04:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy