Extracting a certain number with grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting a certain number with grep command
# 1  
Old 11-23-2011
Extracting a certain number with grep command

Hello Friends,

when I type grep '275' myfile.txt

it gives me all the lines including 275 but it also gives others such as 0.8827588 or 1127507.

I only want the lines including 275. How can I extract only 275 without other numbers including 275.

thanks
# 2  
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:
# 3  
Old 11-23-2011
use -w option for whole word search

PHP Code:
grep -w 275 myfile.txt 
check man page of grep for more details
This User Gave Thanks to amitranjansahu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question