Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a file contain list of path now I want to execute command on each line example :-

file name : rawabdeh .......
command : command

file contains:-

path/no/1/
path/no/2/
path/no/3/

I want to do the following :

command path/no/1/
command path/no/2/
command path/no/3/
share|improve this question
    
Does each line of your file contain multiple paths and do you want to run command on each of the multiple paths on every line ? –  Iain Sep 21 '10 at 14:51
    
no no each line of file conten one path –  Mohammad AL-Rawabdeh Sep 21 '10 at 15:05

3 Answers 3

up vote 1 down vote accepted

Replace input-file, command and output-file as you require

cat input-file | sed 's/^/command /' >output-file

share|improve this answer

This should work for you:

xargs -a "$filename" -n 1 command
share|improve this answer

I'm not sure I'm understanding your request completely, but if you have a list of paths in a file and want to execute the same command on each line in $filename, then you should do:

xargs -n 1 command < $filename
share|improve this answer
5  
xargs -n 1 command <$filename ;) –  krissi Sep 21 '10 at 14:34
    
I'm not sure I'm understanding your request completely, but if you have a list of paths in a file and want to execute the same command on each LINE IN FILE –  Mohammad AL-Rawabdeh Sep 21 '10 at 14:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.