Sponsored Content
Top Forums UNIX for Dummies Questions & Answers grep specific number from a list of numbers Post 302605466 by Corona688 on Wednesday 7th of March 2012 01:23:40 PM
Old 03-07-2012
Please post exactly what you're doing, word for word, letter for letter, keystroke for keystroke. I can't tell what you're doing so don't know why it's going wrong.

You can force grep to print filenames with the -l(filename only) or -H(filename: matching line) options.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Getting unique list of numbers using grep

Hi, I am going to fetch a list of numbers that starts with "0032" from a file with a format like the given below: " 0032459999 0032458888 0032457777 0032451111 0032452222 0032453333 0032459999 0032458888 0032457777 0032451111 0032452222 0032453333 " I want to get a unique... (6 Replies)
Discussion started by: tinku
6 Replies

2. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

3. UNIX for Dummies Questions & Answers

list all files containing 4 digit number using grep

how can i list all files in my home directory that have a 4 digit id number, the line number where the id is located and the id itself not printing the entire line? (5 Replies)
Discussion started by: hobiwhenuknowme
5 Replies

4. Shell Programming and Scripting

iterate through list of numbers and print specific lines with awk

Could someone please point me in the right direction with the following? I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 ... (4 Replies)
Discussion started by: euval
4 Replies

5. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

6. Programming

How to grep the specific string or user's list from the file

I have a file on UNIX system from where I want to grep the list of all users associated to the particular repository.If the user's list is in single line then I fetch all list but if it is in two separate lines it doesn't.I use the below command a=KESTREL-DEV;b=users;cat access_file|grep... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

7. Shell Programming and Scripting

Number of elements, average value, min & max from a list of numbers using awk

Hi all, I have a list of numbers. I need an awk command to find out the numbers of elements (number of numbers, sort to speak), the average value the min and max value. Reading the list only once, with awk. Any ideas? Thanks! (5 Replies)
Discussion started by: black_fender
5 Replies

8. Shell Programming and Scripting

Finding contiguous numbers in a list but with a gap number tolerance

Dear all, I have a imput file like this imput scaffold_0 10558458 10558459 1.8 scaffold_0 10558464 10558465 1.75 scaffold_0 10558467 10558468 1.8 scaffold_0 10558468 10558469 1.71428571428571 scaffold_0 10558469... (5 Replies)
Discussion started by: valente
5 Replies

9. Shell Programming and Scripting

Process a specific number of files ina list

Hello, I have a list of files that was created with, FILES='./'$FOLD'/'$FOLD'_continue/'$OPTIMIZE_ON'/'*'out.txt' I am doing a loop on this list for INPUT in $FILES do ... done but I may not want to process everything. Is there a simple way to just process the first 5,10,n, etc in... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

10. Shell Programming and Scripting

Grep pattern after specific line number in a file

Hi guys, I am running a while loop in a script ro read a file line by line. Now I want to run a grep only on the lines below the line I am that is being read by the while loop. Eg: If my while loop is on line 4 of the file, the grep only runs below line 4 and does not include line 1,2... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies
GREP(1) 						    BSD General Commands Manual 						   GREP(1)

NAME
grep, egrep, fgrep, zgrep, zegrep, zfgrep -- file pattern searcher SYNOPSIS
grep [-abcdDEFGHhIiJLlmnOopqRSsUVvwxZ] [-A num] [-B num] [-C[num]] [-e pattern] [-f file] [--binary-files=value] [--color[=when]] [--colour[=when]] [--context[=num]] [--label] [--line-buffered] [--null] [pattern] [file ...] DESCRIPTION
The grep utility searches any given input files, selecting lines that match one or more patterns. By default, a pattern matches an input line if the regular expression (RE) in the pattern matches the input line without its trailing newline. An empty expression matches every line. Each input line that matches at least one of the patterns is written to the standard output. grep is used for simple patterns and basic regular expressions (BREs); egrep can handle extended regular expressions (EREs). See re_format(7) for more information on regular expressions. fgrep is quicker than both grep and egrep, but can only handle fixed patterns (i.e. it does not interpret regular expressions). Patterns may consist of one or more lines, allowing any of the pattern lines to match a portion of the input. zgrep, zegrep, and zfgrep act like grep, egrep, and fgrep, respectively, but accept input files compressed with the compress(1) or gzip(1) compression utilities. The following options are available: -A num, --after-context=num Print num lines of trailing context after each match. See also the -B and -C options. -a, --text Treat all files as ASCII text. Normally grep will simply print ``Binary file ... matches'' if files contain binary characters. Use of this option forces grep to output lines matching the specified pattern. -B num, --before-context=num Print num lines of leading context before each match. See also the -A and -C options. -b, --byte-offset The offset in bytes of a matched pattern is displayed in front of the respective matched line. -C[num, --context=num] Print num lines of leading and trailing context surrounding each match. The default is 2 and is equivalent to -A 2 -B 2. Note: no whitespace may be given between the option and its argument. -c, --count Only a count of selected lines is written to standard output. --colour=[when, --color=[when]] Mark up the matching text with the expression stored in GREP_COLOR environment variable. The possible values of when can be `never', `always' or `auto'. -D action, --devices=action Specify the demanded action for devices, FIFOs and sockets. The default action is `read', which means, that they are read as if they were normal files. If the action is set to `skip', devices will be silently skipped. -d action, --directories=action Specify the demanded action for directories. It is `read' by default, which means that the directories are read in the same manner as normal files. Other possible values are `skip' to silently ignore the directories, and `recurse' to read them recursively, which has the same effect as the -R and -r option. -E, --extended-regexp Interpret pattern as an extended regular expression (i.e. force grep to behave as egrep). -e pattern, --regexp=pattern Specify a pattern used during the search of the input: an input line is selected if it matches any of the specified patterns. This option is most useful when multiple -e options are used to specify multiple patterns, or when a pattern begins with a dash ('-'). --exclude If specified, it excludes files matching the given filename pattern from the search. Note that --exclude patterns take priority over --include patterns, and if no --include pattern is specified, all files are searched that are not excluded. Patterns are matched to the full path specified, not only to the filename component. --exclude-dir If -R is specified, it excludes directories matching the given filename pattern from the search. Note that --exclude-dir patterns take priority over --include-dir patterns, and if no --include-dir pattern is specified, all directories are searched that are not excluded. -F, --fixed-strings Interpret pattern as a set of fixed strings (i.e. force grep to behave as fgrep). -f file, --file=file Read one or more newline separated patterns from file. Empty pattern lines match every input line. Newlines are not considered part of a pattern. If file is empty, nothing is matched. -G, --basic-regexp Interpret pattern as a basic regular expression (i.e. force grep to behave as traditional grep). -H Always print filename headers with output lines. -h, --no-filename Never print filename headers (i.e. filenames) with output lines. --help Print a brief help message. -I Ignore binary files. This option is equivalent to --binary-file=without-match option. -i, --ignore-case Perform case insensitive matching. By default, grep is case sensitive. --include If specified, only files matching the given filename pattern are searched. Note that --exclude patterns take priority over --include patterns. Patterns are matched to the full path specified, not only to the filename component. --include-dir If -R is specified, only directories matching the given filename pattern are searched. Note that --exclude-dir patterns take prior- ity over --include-dir patterns. -J, --bz2decompress Decompress the bzip2(1) compressed file before looking for the text. -L, --files-without-match Only the names of files not containing selected lines are written to standard output. Pathnames are listed once per file searched. If the standard input is searched, the string ``(standard input)'' is written. -l, --files-with-matches Only the names of files containing selected lines are written to standard output. grep will only search a file until a match has been found, making searches potentially less expensive. Pathnames are listed once per file searched. If the standard input is searched, the string ``(standard input)'' is written. --mmap Use mmap(2) instead of read(2) to read input, which can result in better performance under some circumstances but can cause undefined behaviour. -m num, --max-count=num Stop reading the file after num matches. -n, --line-number Each output line is preceded by its relative line number in the file, starting at line 1. The line number counter is reset for each file processed. This option is ignored if -c, -L, -l, or -q is specified. --null Prints a zero-byte after the file name. -O If -R is specified, follow symbolic links only if they were explicitly listed on the command line. The default is not to follow sym- bolic links. -o, --only-matching Prints only the matching part of the lines. -p If -R is specified, no symbolic links are followed. This is the default. -q, --quiet, --silent Quiet mode: suppress normal output. grep will only search a file until a match has been found, making searches potentially less expensive. -R, -r, --recursive Recursively search subdirectories listed. -S If -R is specified, all symbolic links are followed. The default is not to follow symbolic links. -s, --no-messages Silent mode. Nonexistent and unreadable files are ignored (i.e. their error messages are suppressed). -U, --binary Search binary files, but do not attempt to print them. -V, --version Display version information and exit. -v, --invert-match Selected lines are those not matching any of the specified patterns. -w, --word-regexp The expression is searched for as a word (as if surrounded by '[[:<:]]' and '[[:>:]]'; see re_format(7)). -x, --line-regexp Only input lines selected against an entire fixed string or regular expression are considered to be matching lines. -y Equivalent to -i. Obsoleted. -Z, -z, --decompress Force grep to behave as zgrep. --binary-files=value Controls searching and printing of binary files. Options are binary, the default: search binary files but do not print them; without-match: do not search binary files; and text: treat all files as text. --context[=num] Print num lines of leading and trailing context. The default is 2. --line-buffered Force output to be line buffered. By default, output is line buffered when standard output is a terminal and block buffered other- wise. If no file arguments are specified, the standard input is used. EXIT STATUS
The grep utility exits with one of the following values: 0 One or more lines were selected. 1 No lines were selected. >1 An error occurred. EXAMPLES
To find all occurrences of the word 'patricia' in a file: $ grep 'patricia' myfile To find all occurrences of the pattern '.Pp' at the beginning of a line: $ grep '^.Pp' myfile The apostrophes ensure the entire expression is evaluated by grep instead of by the user's shell. The caret '^' matches the null string at the beginning of a line, and the '' escapes the '.', which would otherwise match any character. To find all lines in a file which do not contain the words 'foo' or 'bar': $ grep -v -e 'foo' -e 'bar' myfile A simple example of an extended regular expression: $ egrep '19|20|25' calendar Peruses the file 'calendar' looking for either 19, 20, or 25. SEE ALSO
ed(1), ex(1), gzip(1), sed(1), re_format(7) STANDARDS
The grep utility is compliant with the IEEE Std 1003.1-2008 (``POSIX.1'') specification. The flags [-AaBbCDdGHhIJLmoPRSUVwZ] are extensions to that specification, and the behaviour of the -f flag when used with an empty pattern file is left undefined. All long options are provided for compatibility with GNU versions of this utility. Historic versions of the grep utility also supported the flags [-ruy]. This implementation supports those options; however, their use is strongly discouraged. HISTORY
The grep command first appeared in Version 6 AT&T UNIX. BSD
July 28, 2010 BSD
All times are GMT -4. The time now is 03:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy