Moving lines of file to command line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Moving lines of file to command line
# 1  
Old 01-07-2014
Moving lines of file to command line

I have a file in which each line is the name of another file. Is there a way to serve them to the command line? For example, if the file contains
Code:
 
 file1.txt
 file2.txt
 file3.txt
 ...
 file9.txt

is there a way to insert them in the command as a batch?

If I ran a command like
Code:
 
 grep "searching_for" file[1-9].txt

it would be replace the file...txt

Thanks in advance
# 2  
Old 01-07-2014
Assuming that the names of the files in your text file don't contain any whitespace characters, your file list isn't "huge", and you're using a shell that recognizes standard command substitution syntax, the following should work:
Code:
grep "searching_for" $(cat name_of_file_containing_file_list)

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 01-07-2014
Or
Code:
< name_of_file_containing_file_list xargs grep "searching_for"

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 01-08-2014
Thank you people. Don's suggestion tried to put a $ in front of the first item, but I got
Code:

 grep "\.sh" `cat list.txt`
 

to work. The xargs suggestion performed as advertised.

Thanks again.
# 5  
Old 01-08-2014
Quote:
Originally Posted by wbport
Thank you people. Don's suggestion tried to put a $ in front of the first item,
No. "$(...)" is just the modern and suggested way to write so-called "process substitution". The way you do it:

Quote:
Originally Posted by wbport
but I got
Code:

 grep "\.sh" `cat list.txt`
 

to work.
is deprecated and you should definitely avoid this. The only reason the shell still understands it is backwards compatibility.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

2. UNIX for Dummies Questions & Answers

sed command to Insert a line before the last four lines of the file

By using sed command, How to insert a new line before the last four lines of the file. Old Line Old Line NEW LINE! Old Line Old Line Old Line Old Line (8 Replies)
Discussion started by: wridler
8 Replies

3. Shell Programming and Scripting

Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone, im new here, and also programming with awk, sed and grep commands on linux. In my text i have many lines with this config: 1 1 4 3 1 1 2 5 2 2 1 1 1 3 1 2 1 3 1 1 1 2 2 2 5 2 4 1 3 2 1 1 4 1 2 1 1 1 3 2 1 1 5 4 1 3 1 1... (3 Replies)
Discussion started by: satir
3 Replies

4. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

5. Shell Programming and Scripting

Moving a line to the end of the file

I have a file with different directories in it. I would need to move one line within the file to the end of the list. Also not there could be blank line in the middle of it. Example /vol/fs1 /vol/fs2 /vol/fs3 /vol/fs4 /vol/fs5 /vol/fs6 /vol/fs7 So I would need /vol/fs2... (3 Replies)
Discussion started by: bombcan
3 Replies

6. Shell Programming and Scripting

Moving 100K file to another folder using 1 command

Hi, I need to move 1000s of files from one folder to another. Actually there are 100K+ files. Source dir : source1 Target dir : target1 Now if try cp or mv commands I am getting an error message : Argument List too long. I tried to do it by the time the files are created in the source... (6 Replies)
Discussion started by: unx100
6 Replies

7. Shell Programming and Scripting

Moving file using test command

My process creates file like abc.20090427.txt i.e abc.date.txt next time when my process it has to detect if any previous "abc" exist. If exist then move to archive and create a new abc file. I am using test command but it doesnt allow wild card. if ] then mv abc.*.txt... (7 Replies)
Discussion started by: pinnacle
7 Replies

8. UNIX for Dummies Questions & Answers

Command file for moving emails

hey guys. I'm trying to create a command file that moves my emails to a specified folder according to a keyword that is in the subject. like move emails with "hey" in the subject to a folder that exists in my mail folder named "hey". how do I go about that? thanx. (9 Replies)
Discussion started by: ~samantha89~
9 Replies

9. Shell Programming and Scripting

deleting particular lines and moving a line up using perl/sed

Hi, I need convert a dump file in the following format : (please note that line numbers are provided for easy look) Original file: 1 2007-10-2482.90 No trade 0 0.00 100000.00 2 100000.00 3 0.00 4 HOLD 5 2007-10-2589.75 Bought 1114 1114 100000.00 0.00 ... (5 Replies)
Discussion started by: sabyasm
5 Replies

10. Shell Programming and Scripting

Moving lines within a txt file

A newbie to shell scripting..... I need some assistance in doing the following: I have a system generated text file(a makefile basically). Before I can execute the make command, I need to modify one section of this generated file. The generated section is as follows: # INCLUDE macro... (5 Replies)
Discussion started by: innocentspirit
5 Replies
Login or Register to Ask a Question