Listing all digits behind the comma with grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing all digits behind the comma with grep
# 1  
Old 04-22-2012
Listing all digits behind the comma with grep

Hello, Unix-Forums!

Code:
1.23456789

This an example number. It can be any number. I want grep to only find the digits behind the "."
That means
Code:
23456789

should be the output in this case.

How would I do that?
# 2  
Old 04-22-2012
Try:
Code:
nr=1.23456789
echo "${nr#*.}"


Last edited by Scrutinizer; 04-22-2012 at 03:46 PM.. Reason: Nscott is right, one # was superfluous
# 3  
Old 04-22-2012
So is this in a stream or already in a shell variable? Which shell?

For example if it is a string you can use your shells parameter expansion (bash/ksh):
Code:
var='1.23456789'
echo "${var#*.}"

a stream:
Code:
$ echo 1.23456789 | awk -F. '{print $2}'
23456789

$ echo 1.23456789 | cut -d. -f2
23456789

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

3. Shell Programming and Scripting

How to grep after the first comma till the next comma in a line

Hi Can any one pls tell me how to grep this line POPULATION,69691,20120509 I want the number 69691 from the above line. How to grep from the first comma till the next comma. Thank You.:confused: (8 Replies)
Discussion started by: rxg
8 Replies

4. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

5. UNIX for Dummies Questions & Answers

how to use grep: finding a string with double quotes and multiple digits

I have a file with a lot of lines (a lot!) that contain 10 digits between double quotes. ie "1726937489". The digits are random throughout, but always contain ten digits. I can not for the life of me, (via scouring the internet and grep how-to manuals) figure out how to find this when I search.... (3 Replies)
Discussion started by: titusbass
3 Replies

6. UNIX for Dummies Questions & Answers

locate special characters and digits using grep

Hello, i have a file called test hello1 "how" are you4 good"bye" good7bye i am trying to print all lines from test that either end with a digit or contain a double quote character anywhere on the line. i did grep -n '$' test and was able to print lines ending with digits. i also did... (2 Replies)
Discussion started by: hobiwhenuknowme
2 Replies

7. Shell Programming and Scripting

grep/matching help with long listing of directories

How do I get this to work? cat somefile | grep "-rw-r--r-- 1 root wheel 287 Sep 10 15:12 shells~" This is the the desired output -rw-r--r-- 1 root wheel 287 Sep 10 15:12 shells~ I basically want an exact match of the line I am grepping for, the special characters and... (5 Replies)
Discussion started by: streetfighter2
5 Replies

8. Shell Programming and Scripting

AWK script for directory listing using GREP

Hi, All - script1.awk contains the following script: BEGIN { printf "The following are directory files:" "ls -l | grep '^d' | {print $0}" printf "There were "NR" directories in this list." } When I run the script, Here is what I get: $ awk -f... (4 Replies)
Discussion started by: ora_umair
4 Replies

9. UNIX for Dummies Questions & Answers

Grep a line with between 3 and 5 digits

Hi, I am having problems using grep to extract only 3,4 or 5 digit numbers from a text file, using: grep '\<\{3,5\}\>' test.txt or grep '\{3,5\}' test.txt or egrep '{3,5}' test.txt I would appreciate any help that anyone can give me thanks (1 Reply)
Discussion started by: ceemh3
1 Replies

10. UNIX for Dummies Questions & Answers

listing files along with grep -v

When I run the command ls | grep -v SNMP It outputs all the files into one column. How can I list them in multiple columns? (5 Replies)
Discussion started by: charlie11k
5 Replies
Login or Register to Ask a Question