LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-01-2015, 05:59 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 37
How to extract values from line?


I have a file in which every disk path is stored in disk parameter . However this file is dynamic and number of disk numbers can increase/decrease .
Is there a way to store this disk path values in file .

For example
This is a sample file .

disk = ['file:/OVS/repository/file1.img,xvda,w', 'file:/OVS1/repository/file1.img,xvdb,w']

I want diskpath.txt to be filled like
/OVS/repository/file1.img
/OVS1/repository/file1.img

i tried awk with my limited knowledge but couldn't able to figure the solution.
please help .
 
Old 04-01-2015, 06:24 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,133

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
If the data is always that well structured, I might be inclined to use colon and comma as field separators - that will give you well defined fields to print regardless of number of "file:" entries per record.

Have a go and we may be able to help if you still have trouble.
 
1 members found this post helpful.
Old 04-01-2015, 06:32 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
syg00 i tried using awk but with only one field separator using -F .

How to pick up values using two separator here its : and , . and as the values can increase decrease i m not sure how to determine the value e.g. $2 $3 in print .
 
Old 04-01-2015, 06:33 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,913

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Is this suitable?
awk 'BEGIN { FS="[][,'"'"':= ]*" } { print $3" "$7 } '
 
Old 04-01-2015, 06:52 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,133

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
pan64 has shown one way to specify multiple separators - it can be done similarly with -F.
I would work on the premise that the number of files may be variable - 2 mostly maybe, but maybe only one, or more than 2. Use NF as an indicator.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i extract values from a excel file using a shell script VijayB Linux - Newbie 1 08-01-2014 12:55 AM
[SOLVED] Extract only unique values from a file shivaa Linux - Newbie 11 10-17-2012 09:56 AM
Using Perl to extract values from an HTML file zero_maniac Programming 2 07-14-2012 10:11 PM
extract values from array PHP Randall Slack Programming 2 07-02-2009 06:52 AM
Need to extract certain values from kudzu-output. MheAd Linux - Newbie 3 07-02-2008 05:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:03 PM.

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