LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-02-2014, 02:32 AM   #1
PelleP
LQ Newbie
 
Registered: Aug 2014
Posts: 14

Rep: Reputation: Disabled
Simple but can't figure it out: print or store value from egrep statement


Hi!

Quick q:

I want to filter out only the location from a file path. I.e. getting only the string /root/ from
the string /root/file.db .
I do this using regexp, no problem. So if I have the file path text string in a file I'm getting what I want using:
Code:
egrep '^(.*[\\\/])' /path/to/file
which returns
/root/file.db with /root/ in red color.

But how the h**l do I extract that into a variable? If I use awk with the same regexp it prints the whole line.

And
Code:
var=$(egrep '^(.*[\\\/])' /path/to/file)
also stores the whole line into var.

Regards,
Pelle
 
Old 09-02-2014, 04:27 AM   #2
jensd
LQ Newbie
 
Registered: Jun 2014
Posts: 13

Rep: Reputation: Disabled
You can use dirname to do this:
Code:
dirname /root/test
/root
 
Old 09-02-2014, 04:41 AM   #3
PelleP
LQ Newbie
 
Registered: Aug 2014
Posts: 14

Original Poster
Rep: Reputation: Disabled
That was a much easier way!
Thanks a lot!

/P
 
  


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
EASY scripting question - trying to figure out a test statement Elendrael Linux - Newbie 1 09-16-2007 07:52 PM
Can't seem to figure out how to print to a network printer Ekim8587 Linux - Networking 3 11-16-2005 09:06 AM
Print statement never executed Linh Programming 3 08-14-2003 12:46 PM
very very simple identd question.. cant figure out myself.. need help!! kublador Linux - Networking 1 06-10-2003 03:17 AM
retard can't figure out simple things Karnak Linux - Hardware 13 10-05-2002 12:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:26 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
Open Source Consulting | Domain Registration