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 |
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! |
Quote:
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 ' ' |
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` Code:
command_needing_arguments `command_provide_arg1` `command_provide_arg2` `...` `command_provide_argN` hope this helps |
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/ |
All times are GMT -5. The time now is 04:37 AM. |