Question concerning xargs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question concerning xargs
# 1  
Old 03-13-2007
Question concerning xargs

Hello... I happened upon this site when searching for an answer, and I consider myself a UNIX dummy, so here I am!

Here's my issue: I'm trying to use xargs to strip blank lines out of a group of files and copy the output to another directory, and I just can't figure out the syntax. Here's what I have:

xargs -I {} sed '/^$/d' {} < FILE_NAME_LIST.dat

Which works, but I can't figure out how to output it. If I use

xargs -I {} sed '/^$/d' {} < FILE_NAME_LIST.dat > /some/directory

or

xargs -I {} sed '/^$/d' {} > /some/directory < FILE_NAME_LIST.dat

I get a message stating that it's a directory, as if expecting the output to be a single file. If I use

xargs -I {} sed '/^$/d' {} > /some/directory/{} < FILE_NAME_LIST.dat

Then everything outputs to a file named '{}', instead of separate files based on the filenames in FILE_NAME_LIST.dat. I'm sure it's just a simple thing, but I can't think through it. Any takers? Thanks in advance!
# 2  
Old 03-13-2007
Quote:
Originally Posted by cp27316
Hello... I happened upon this site when searching for an answer, and I consider myself a UNIX dummy, so here I am!

Here's my issue: I'm trying to use xargs to strip blank lines out of a group of files and copy the output to another directory, and I just can't figure out the syntax. Here's what I have:

xargs -I {} sed '/^$/d' {} < FILE_NAME_LIST.dat

Which works, but I can't figure out how to output it. If I use

xargs -I {} sed '/^$/d' {} < FILE_NAME_LIST.dat > /some/directory

or

xargs -I {} sed '/^$/d' {} > /some/directory < FILE_NAME_LIST.dat

I get a message stating that it's a directory, as if expecting the output to be a single file. If I use

xargs -I {} sed '/^$/d' {} > /some/directory/{} < FILE_NAME_LIST.dat

Then everything outputs to a file named '{}', instead of separate files based on the filenames in FILE_NAME_LIST.dat. I'm sure it's just a simple thing, but I can't think through it. Any takers? Thanks in advance!
You cannot redirect output to a directory; it must be to a file.
# 3  
Old 03-13-2007
I see that, but is there any way to use the placeholder ('{}' in this case) to denote individual file names for the output? For instance, if FILE_NAME_LIST.dat contained the following lines:

File1.dat
File2.dat
File3.dat


Is there any way to create/execute these three lines using xargs or any other command?

sed '/^$/d' File1.dat > /some/directory/File1.dat
sed '/^$/d' File2.dat > /some/directory/File2.dat
sed '/^$/d' File3.dat > /some/directory/File3.dat

Unlike the listed files, the ones in question will have vastly different filenames, so I won't be able to just loop through them with some iterator to get the desired effect, unfortunately.
# 4  
Old 03-13-2007
Why make it so complicated?

Code:
while read file ; do
    sed '/^$/d' $file > /other/dir/$file
done < FILE_NAME_LIST.dat

# 5  
Old 03-14-2007
If I knew it was that easy, I never would have been here! I was too stuck on xargs, I couldn't think of a different way to do it, but that makes perfect sense, and worked like a charm. Thanks so much!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Xargs

Hi, can anyone tell me in detail ? what the following do in detail ? I am trying to get a largest number in a list Thanks Tao LARGEST=$(echo $* | xargs -n1 | sort -nr | tail -1) (3 Replies)
Discussion started by: ccp
3 Replies

2. Shell Programming and Scripting

Xargs

Hello, I need some help with xargs $ ls aaa bbb ccc ddd$ ls | xargs -I{} ls -la {} -rw-rw-r--. 1 xxx xx 0 May 30 20:04 aaa -rw-rw-r--. 1 xxx xx 0 May 30 20:04 bbb -rw-rw-r--. 1 xxx xx 0 May 30 20:04 ccc -rw-rw-r--. 1 xxx xx 0 May 30 20:04 dddit's possible to have output like this with... (3 Replies)
Discussion started by: vikus
3 Replies

3. Shell Programming and Scripting

Help with xargs

Using the bash shell I'm trying to either create a command for the command line or a script that will show netstat info for a given process name. Here is an example of what I'm trying to do:$ ps aux |grep catalina |grep -v grep | awk '{print $2}' 5132 $ netstat -nlp |grep 5132 (Not all processes... (11 Replies)
Discussion started by: axiopisty
11 Replies

4. Shell Programming and Scripting

xargs question

Suppose your piping a path into xargs and want to print the name along with the total size: find . -maxdepth 1 | xargs -I {} echo "{} ]*//g'`]" This won't work because {} ceases having its special meaning within the ``. How to preserve it? Thanks Code tags for code, please! (10 Replies)
Discussion started by: stevensw
10 Replies

5. Shell Programming and Scripting

xargs

I have dir with many files ( close to 4M ) . $ ls -la total 76392 drwxr-xr-x 10 oracle dba 512 Jun 06 14:39 . drwxr-xr-x 11 oracle dba 512 Dec 20 13:21 .. drwxr-xr-x 2 oracle dba 39074816 Jun 15 14:07 ad I am trying to delete them using... (8 Replies)
Discussion started by: talashil
8 Replies

6. Shell Programming and Scripting

xargs

Dear all , any suggest on xargs to combine from (1.txt and 2.txt) to output.txt ? thanks a lot. 1.txt 0123 BUM-5M BUM-5M 93490481 63839 0124 BUM-5M BUM-5M 112112 ... (3 Replies)
Discussion started by: samoptimus
3 Replies

7. Shell Programming and Scripting

Help with xargs

hi Could any one please tell me the option using which we can run multiple commands using xargs I have list of files, I want to run dos2unix and chmod at one shot on them I tried google n searched man pages but couldnt really find the solution , please help right now im doing this ls... (4 Replies)
Discussion started by: sunilmenhdiratt
4 Replies

8. Shell Programming and Scripting

Using xargs

hi i just want to know that how do we use xargs command to find files which are greater than specified memory in a given directory (6 Replies)
Discussion started by: sumit the cool
6 Replies

9. UNIX for Advanced & Expert Users

xargs -P

I discovered that GNU's xargs has a -P option to allow its processes to run in parallel. Great! Is this a GNU thing, or is it supported by other platforms as well? (4 Replies)
Discussion started by: otheus
4 Replies

10. Shell Programming and Scripting

why we use xargs..

hi , can anyone help me by saying why we use xargs.. is it acing like a place holder..? thanks, Krips. (3 Replies)
Discussion started by: kripssmart
3 Replies
Login or Register to Ask a Question