LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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


Closed Thread
  Search this Thread
Old 03-20-2010, 11:06 AM   #1
Alkass
Member
 
Registered: Mar 2010
Posts: 47

Rep: Reputation: 0
How to read a line in a file and use it as argument


Hi

I want to do this

read a files's specific line but return as argument only part of it ie

...

value # this is mass

value2 # this is force

so, how can I get / use the $value and $value2 as arguments for some other file and skip the rest of the line(s) ? of course, the values are different everytime, but the comment always the same, as well as the position of the lines in the file

Thanks in advance
 
Old 03-20-2010, 11:24 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,713
Blog Entries: 27

Rep: Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055Reputation: 2055
Hi,

Welcome to LQ!

So you've shown us your need! What's your deed?
We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist.

'Geek Stuff' has some examples.

Just a few more links to aid you to gaining some understanding;
Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Newbie Admin Guide
LinuxSelfHelp
Getting Started with Linux

These links and others can be found at 'Slackware-Links' .
More than just SlackwareŽ links!
 
Old 03-20-2010, 12:59 PM   #3
nonamenobody
Member
 
Registered: Oct 2002
Posts: 138

Rep: Reputation: 22
Quote:
Originally Posted by Alkass View Post
Hi

I want to do this

read a files's specific line but return as argument only part of it ie

...

value # this is mass

value2 # this is force

so, how can I get / use the $value and $value2 as arguments for some other file and skip the rest of the line(s) ? of course, the values are different everytime, but the comment always the same, as well as the position of the lines in the file

Thanks in advance
Are you doing this from the shell? is that shell bash?

Grep is the easy way to get the lines. If these are the only lines that contain the words mass and force, grep for that. If they are the only lines which contain value and value2, grep for that.
If not, you'll have to rely on the line number e.g. if it is the 3rd line use 'tail -n +3 yourfilename |head -1'.

Once you have the line you need, you can probably use cut to get what you want. E.g. cut -f 2 -d ' '
 
Old 03-20-2010, 02:09 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,215

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
next step once you get a command that extracts the data from the file is to pass it to the other command
you can do that by enclosing the command in back quotes ` (shift+~) eg
Code:
echo `cat /etc/fstab` `cat /etc/fstab`
will pass the output of the cat fstab command to the echo twice, you could use that like this

Code:
command_needing_arguments `command_provide_arg1` `command_provide_arg2` `...` `command_provide_argN`
also depending on how you ultimately get the value from line(s)/word(s) for each of the arguments you could write that into a shell script that executes the big command and simply taking the line(s)/word(s) as it's arguments

hope this helps

Last edited by frieza; 03-20-2010 at 02:11 PM.
 
Old 03-20-2010, 02:19 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,716

Rep: Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751Reputation: 1751
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Continue here:
http://www.linuxquestions.org/questi...gument-796688/
 
  


Closed Thread


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
How to read a line in a file and use it as argument Alkass Programming 25 04-21-2010 09:49 PM
How can I read a file line by line and add it to a loop in another file? astroumut Linux - Newbie 7 08-24-2009 04:37 AM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-14-2008 11:52 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM


All times are GMT -5. The time now is 11:32 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