LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2011, 01:25 PM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
extract only number in a path in bash


I've these path:
Code:
xxx/yyy/zzz/0908/aaa/a.txt
xxx/yyy/zzz/0909/aaa/a.txt
xxx/yyy/zzz/0910/aaa/a.txt
fff/ggg/hhh/iii/jjj/0911/aaa/a.txt
fff/ggg/hhh/kkk/0912/aaa/a.txt
and I would like to extract only the number, so that I've get the result

Code:
0908
0909
0910
0911
0911
How can I do it in bash?
 
Old 03-17-2011, 01:26 PM   #2
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
I've got the answer.

echo "abc 123 +@#" | egrep "[0-9]{1,}" -o
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
extract last number from filename csegau Linux - Newbie 8 05-28-2010 07:24 AM
How to extract the interface number from ifconfig -a pooppp Linux - Networking 4 08-04-2008 04:54 AM
HELP!!! how to use grep to extract a number khong1010 Programming 6 04-18-2008 12:01 AM
Best/Right way to extract disk serial number? itnaa Linux - Hardware 4 08-21-2007 11:13 AM
php question - how to extract line number ?? antony_csf Programming 5 09-15-2004 08:08 PM


All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration