how to grep a number from output line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to grep a number from output line
# 1  
Old 11-23-2009
how to grep a number from output line

I`m having a output shown below,

CFR 235,BBC DM-2 ALL
CFR 111,BBC DM-2 ALL
CFR 333,BBC DM-2 ALL

from the above Output i want to use 235,111,333 as input for other purpose.
these no always change every time i run script.so please suggest me the way i could do it with example,i have tried grep command but as no changes this commands fail the grep right number.also tell the way i can use these number as input for other command.
# 2  
Old 11-23-2009
for example
Code:
echo "CFR 235,BBC DM-2 ALL
CFR 111,BBC DM-2 ALL
CFR 333,BBC DM-2 ALL" | grep -Eo "[0-9]{3}" | sort -g
111
235
333

# 3  
Old 11-23-2009
One way:

Code:
egrep -o "[0-9]{3}" in.file

Another:

Code:
cat in.file | awk -F "[ ,]" '{print $2}'

# 4  
Old 11-23-2009
Code:
sed 's/.* \([0-9]*\),.*/\1/' < file

# 5  
Old 11-23-2009
Java

Quote:
Originally Posted by nitin_aaa27
CFR 235,BBC DM-2 ALL
CFR 111,BBC DM-2 ALL
CFR 333,BBC DM-2 ALL
awk '{ print $2 }' | awk -F, '{ print $1 }' | tr '\n' ','
# 6  
Old 02-24-2010
Dear friend ,

You can use the following way also, to get the number only

The input file contain the following content

CFR 235,BBC DM-2 ALL
CFR 111,BBC DM-2 ALL
CFR 333,BBC DM-2 ALL

Code:
 
cut -b 5-7 file

Here "-b" is used to extract the data from the file using the bytes. Here I use the bytes between the 5 to 7
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies

2. UNIX for Beginners Questions & Answers

How do I use grep to grab prime number output from my factor program?

I have a factor program that runs and outputs to stdout all the prime numbers that are specified in the given paramters, in this case 30000000-31000000. Command: factor/factor 30000000-31000000 Sample output: 30999979 = 30999979 30999980 = 2^2 5 11 140909 30999981 = 3 10333327... (6 Replies)
Discussion started by: steezuschrist96
6 Replies

3. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

4. UNIX for Dummies Questions & Answers

Grep SQL output file for greater than number.

Hi, This is my first post. I have a korn shell script which outputs a select statment to a file. There is only one column and one row which contains a record count of the select statement. The select statement looks something like this: SELECT COUNT(some_field) AS "count_value" ... (2 Replies)
Discussion started by: MurdocUK
2 Replies

5. UNIX for Dummies Questions & Answers

Grep or other ways to output line above and/or below searched line

Hi all, Would like to know how I could search for a string 'xyz' but have the output show the line plus the line above and/or below all lines found. eg. search for xyz from file containing: abc 12345 asdf xyz asdfds wwwww kjkjkj ppppp kkkxyz eeee zzzzz and the output to... (2 Replies)
Discussion started by: sammac
2 Replies

6. Shell Programming and Scripting

Using grep to extract line number

I'm trying to use grep to get the line number only. This is the command I'm using: grep -n "Content-Disposition: attachment" mbox The output I get is: 45:Content-Disposition: attachment; filename="test.txt" So now I just want to get the line number (45) from this output. Can someone... (8 Replies)
Discussion started by: mskarica
8 Replies

7. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies

8. Shell Programming and Scripting

grep the string with the line number

Dear Masters, Here i have some doubts can anyone clarify?. Is it possible to grep the lines by specifying the line numbers. I know the line number which i want to grep. example: grep 40th line filename grep 50th line filename Need ur comments. (4 Replies)
Discussion started by: salaathi
4 Replies

9. UNIX for Dummies Questions & Answers

Get Filename and Line Number using grep

Hi, I am using the Korne shell to try and get the filename, line number and the line of text using grep e.g. find ./ -type f -name "*.java" -exec grep -nf test.txt '{}' \; (test.txt contains strings to search) will return the line number and the line of text. grep -l would return the... (4 Replies)
Discussion started by: ceemh3
4 Replies

10. UNIX for Dummies Questions & Answers

is there any why to get the number of line in grep result ?

Hello all when I do simple grep on file im getting the results of "filename : stringResult " is there any way to present also the line number in the file ? (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question