Sponsored Content
Top Forums Shell Programming and Scripting Extracting a certain number with grep command Post 302575823 by ahamed101 on Wednesday 23rd of November 2011 01:59:07 AM
Old 11-23-2011
Code:
grep -w '275' myfile.txt

man grep
Quote:
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning
of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-
word constituent character. Word-constituent characters are letters, digits, and the underscore.
--ahamed
This User Gave Thanks to ahamed101 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting 10 digit number from txt files

Hi, Was wondering if you could give me an example of extracting a 10 digit number from 5 txt files using a regular expression (the number is always different ) and storing the numbers in variables Thanks C19 (9 Replies)
Discussion started by: c19h28O2
9 Replies

2. Shell Programming and Scripting

Extracting a Number from Passage

( Database Connection Information Database server = DB2/AIX6000 8.1 SQL authorization ID = LAKNAR Local database alias = SAMPLE ROWSAFFECTED ------------ 1 1 record(s) selected. DB20000I The SQL command completed successfully. DB20000I The TERMINATE... (1 Reply)
Discussion started by: laknar
1 Replies

3. Shell Programming and Scripting

extracting a number from a string

Hi everyone, I have a string as follow ts1n65ulpa4096x16m16_130a_ss1p08v125c i would like to extract 4096 and 16 from string and save it into two variable. but this string could also have the form ts1n65ulpa32x16m16_130a_ss1p08v125c therefore the number before "x" could be 2 or 3 digits. i use... (6 Replies)
Discussion started by: ROOZ
6 Replies

4. Shell Programming and Scripting

number of lines returned from a grep command

hi all, from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ?? thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies

5. Shell Programming and Scripting

Extracting N lines match number X of a pattern

Hi All, as the title says I need to extract N lines after match number X of a pattern. e.g. 111 xxx xxx 111 yyy yyy 111 www www 111 zzz zzz I would like to extract the two lines after the second 111 occurrence. I tried with grep but I didn't find any options to do that. Any... (11 Replies)
Discussion started by: f_o_555
11 Replies

6. Shell Programming and Scripting

extracting Number variable and the following digits.

HI all, I have output of something like this: crab: ExitCodes Summary >>>>>>>>> 12 Jobs with Wrapper Exit Code : 50117 List of jobs: 1-12 See https:///twiki/something/ for Exit Code meaning crab: ExitCodes Summary >>>>>>>>> 5 Jobs with Wrapper Exit Code : 8001 List of... (20 Replies)
Discussion started by: emily
20 Replies

7. Shell Programming and Scripting

extracting number of rows

if > wc -l data.txt > 100 (meaning there are 100 rows) i want to assgn 100 as n so that if i do >echo n it would give me 100 Thanks (5 Replies)
Discussion started by: johnkim0806
5 Replies

8. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

9. Shell Programming and Scripting

Extracting fixed length number from a text file

Hi, I have a text file with sample records as CASE ID: 20170218881083 Original presentment record for ARN not found for Re-presentment I want to extract the 23 digit number from this file. I thought of using grep but initially couldn't extract the required number. However, after... (16 Replies)
Discussion started by: dsid
16 Replies

10. UNIX for Beginners Questions & Answers

Grep command to show the number of results

Hi I wanted to know if there is an option in grep command to show the number of results (not the number of lines of findings). Thanks (14 Replies)
Discussion started by: abdossamad2003
14 Replies
DLOCATE(1)							      dlocate								DLOCATE(1)

NAME
dlocate - program to view debian package information SYNOPSIS
dlocate [OPTIONS] [command] [ package... | PATTERN...] DESCRIPTION
dlocate is a fast alternative to dpkg for queries like `dpkg -L' and `dpkg -S' COMMANDS
(none) List all records where either the package name or the filename matches PATTERN. Note that dlocate uses GNU grep, so normal regexp metacharacters need to be taken into account or avoided by using the '-F' (Fixed String) grep option. For example, to search for `/usr/bin/[', you might try: dlocate '/usr/bin/[' or dlocate -F '/usr/bin/[' -S list all records where only the filename matches PATTERN. Note that dlocate uses GNU grep, so normal regexp metacharacters need to be taken into account. Fixed String searches are incompat- ible with -S For example, to search for `/usr/bin/[', you need to type: dlocate '/usr/bin/[' -l Regexp-enhanced emulation of `dpkg -l'. Shows all packages which match package. Internally this uses grep on a file containing the reformatted output output of 'dpkg -l' (four fields separated by tabs; status, package-name, installed version, short description) so it will return packages whose version or short description matches, too. Various flavours of regular expression are supported. For example, Extended Regexp: dlocate -l '^..[[:space:]]libc6' or Perl Regexp: dlocate -P -l '^..slibc6' Both of these will list all the packages whose names start with `libc6'. Note that because of the difference between regular expressions and dpkg's shell-style pattern matching, the output from dlocate -l is occasionally different to the output from dpkg -l. This is not a bug, regular expressions are far more flexible than shell pattern matching. This is the way dlocate is supposed to run, but it may require some knowledge of regular expressions to get the output you want. -k List package names of installed kernels and all related packages -K Detailed list of installed kernels and all related packages -L List all files in package. -s Print status of package. -ls `ls -ldF' of all files in package. -lsconf `ls -ldF' of conffiles in package. -conf List conffiles in package. -du `du -sck' of all files in package. -md5sum List md5sums (if any) of package. -md5check Check md5sums (if any) of package. -man List man pages (if any) in package. -lsman List full path/filenames of man pages (if any) in package. -lsbin List full path/filenames of executable files (if any) in package. OPTIONS
--filename-only Only output file names when searching for files --package-only Only output package names when searching for files -w, --word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or fol- lowed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. -i, --ignore-case Ignore case distinctions in the PATTERN -E, --extended-regexp Interpret PATTERN as an extended regular expression. This is the default. -F, --fixed-strings Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. -G, --basic-regexp Interpret PATTERN as a basic regular expression. -P, --perl-regexp Interpret PATTERN as a Perl regular expression. This is considered to be highly experimental within GNU grep and may warn of unim- plemented features. -h, -H, --help Produces a short help message and exits. -V, --version Display dlocate's version number and exit. -v, --verbose, --debug Produce verbose debugging output FILES
/etc/default/dlocate Configuration file with default options. Currently the only option is to enable/disable gzip compression of /var/lib/dlocate/dlo- catedb. /var/lib/dlocate/dlocatedb plain text listing of all files belonging to all packages (optionally compressed) /var/lib/dlocate/dpkg-list Listing of all packages known to dpkg. This contains the reformatted output output of 'dpkg -l'. The file format is four fields separated by tabs: status [TAB] package-name [TAB] installed version [TAB] short description EXAMPLES
To find which package `/usr/bin/[' belongs to: dlocate '/usr/bin/[' To view all man pages contained within the dpkg package: man $(dlocate -man dpkg) To purge kernel version 2.6.28.7 and all related module packages: dlocate -k | grep -- -2.6.28.7 | xargs apt-get purge To check the md5sums of the dlocate package: dlocate -md5check dlocate To use dpkg-repack to make a backup copy of all installed mythtv packages just before upgrading them: dlocate -l mythtv | grep '^.i' | awk '{print $2}' | xargs dpkg-repack # dlocate -l mythtv | grep '^.i' | awk '{print $2}' | xargs dpkg-repack dpkg-deb: building package `libmythtv-perl' in `./libmythtv-perl_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv' in `./mythtv_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-backend' in `./mythtv-backend_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-common' in `./mythtv-common_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-database' in `./mythtv-database_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-doc' in `./mythtv-doc_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-frontend' in `./mythtv-frontend_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-perl' in `./mythtv-perl_0.21.svn20090414-0.0_amd64.deb'. dpkg-deb: building package `mythtv-status' in `./mythtv-status_0.9.0-5_amd64.deb'. dpkg-deb: building package `mythtv-themes' in `./mythtv-themes_0.21-0.0_amd64.deb'. dpkg-deb: building package `mythtvfs' in `./mythtvfs_0.5.2-2_amd64.deb'. dpkg-deb: building package `python-mythtv' in `./python-mythtv_0.21.svn20090414-0.0_amd64.deb'. ENVIRONMENT VARIABLES
COLUMNS Sets the number of columns dlocate should use when displaying formatted text. Currently only used by -l. Values lower than 80 are ignored. SEE ALSO
dpkg(1), update-dlocatedb(8), grep(1) and grep-dctrl(1). AUTHOR
dlocate was written by Jim Pick <jim@pick.com> and Craig Sanders <cas@taz.net.au>. dlocate is Free Software licensed under the GNU General Public License. Debian Project 2009-06-03 DLOCATE(1)
All times are GMT -4. The time now is 07:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy