Execute all files at once


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute all files at once
# 1  
Old 03-16-2013
Execute all files at once

Hi everyone, i'm newbie to unix!
If I have many files named by temp1.txt, temp2.text, temp3.txt,..... I want to introduce some key words at the top of each of files. The script (named bimbo) I tried is shown.
Code:
#!/bin/csh
set FILE=$1
echo $FILE
set OUT=$1
echo '%tage='$FILE  >> x_$FILE    
sed -e  '2i\%aveg=330'   x_$FILE  > x1  
sed -e  '3i\temp=3000MB'  x1 > x2
sed -e '4i\%rain=8'  x2  > x3
sed -e '5i\@skyhigh' x3  > x4
sed -e '6i\ '   x4> x5      # insert blank line
echo 'topic:'$FILE.txt >>  x5    # file names
sed -e '8i\ ' x5> x6
sed -e '9i\bm nnm'   x6 > x7
cat x7 $FILE.txt >  $OUT.out

when I execute: ./bimbo temp1 it works but not for multiple files at once /bimbo *.txt,? so how do i make to excetue all files at once? thanks

Last edited by jim mcnamara; 03-17-2013 at 12:16 AM..
# 2  
Old 03-16-2013
This might work:
Code:
ls temp*.txt | xargs -n 1 bimbo

The functionality could also be built into the bimbo script, so you could run bimbo temp*.txt, but the above way will probably work.

Of course, I hope you are saving copy of original files to verify bimbo script working correctly.
# 3  
Old 03-16-2013
Quote:
Originally Posted by hanson44
This might work:
Code:
ls temp*.txt | xargs -n 1 bimbo

The functionality could also be built into the bimbo script, so you could run bimbo temp*.txt, but the above way will probably work.

Of course, I hope you are saving copy of original files to verify bimbo script working correctly.
If there are numerous temp*.txt files so that it exceed the ARG_MAX you could get an "argument list too long" error.
better use the "for" SHELL built-in
Code:
for i in temp*.txt
do bimbo $i
done

# 4  
Old 03-16-2013
Are you sure about that? You may be right. But I thought part of the point of xargs was to avoid such problems. It seems to work, no error message, on a test I did. Any counter-example?
Code:
$ getconf ARG_MAX
2621440
$ seq 2621441 | xargs -n 1 echo | tail -2 # takes a while to run!
2621440
2621441

# 5  
Old 03-17-2013
Quote:
Originally Posted by hanson44
Are you sure about that? You may be right. But I thought part of the point of xargs was to avoid such problems. It seems to work, no error message, on a test I did. Any counter-example?
Code:
$ getconf ARG_MAX
2621440
$ seq 2621441 | xargs -n 1 echo | tail -2 # takes a while to run!
2621440
2621441

The ARG_MAX (or may be LINE_MAX) issue is with ls temp*.txt and not with xargs.
This User Gave Thanks to elixir_sinari For This Post:
# 6  
Old 03-17-2013
Thanks.
# 7  
Old 03-18-2013
If you want to give a test (may takes a while but still) :
Code:
seq 2621441 | while read n
do touch tst_$n
done

then try :
Code:
ls tst_* | tail

then try :
Code:
for i in tst_*
do echo $i
done | tail

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute a Command in a .Dat File and use it in other Files

We have a process where we store the database password in a config file like below from where the password is picked up and used in Database Scripts ID, Password But we now have a Audit Requirement not to have the passwords in Config Files directly. We have a command which could fetch the... (2 Replies)
Discussion started by: infernalhell
2 Replies

2. Shell Programming and Scripting

Find files and execute commands on these files (advanced)

So, I need to find a bunch of files and delete them (this example, but sometimes I need it for something else) and my trusty go-to command has always been: find . -type f -name '*file*' | xargs -I## rm '##' Works wonders... But: touch file\ file\'.txt touch file.txt touch file\ file.txt... (6 Replies)
Discussion started by: Mr.Glaurung
6 Replies

3. Programming

[Solved] Cannot execute file that include files

Iam trying to execute a file that include many files but it seems my main copy.c can't read anyone of them ----------------------------------------------------------------------------------------- Copy.c #include <sys/stat.h> #include <fcntl.h> #include "tlpi_hdr.h" #ifndef BUF_SIZE /*... (2 Replies)
Discussion started by: fwrlfo
2 Replies

4. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

5. Shell Programming and Scripting

How to execute script on files in another directory?

Hi Guys, Is there any way I can execute my bash script on files in a different folder than what the script is in? Here is an excerpt of my script: #!/usr/bin/bash input_path="/cygdrive/c/files" output_path="/cygdrive/c/files/data" #script uses files from /cygdrive/c/files directory,... (1 Reply)
Discussion started by: npatwardhan
1 Replies

6. UNIX for Dummies Questions & Answers

For Loop to execute a command on a series of files

Hello, I have a set of input data that I split into batches using the following command: split -l 4000000 MyInput.in Split_a Once I get the split files, I run a certain command on the split files that spews an output. So far I have been doing it without a for loop. How can I translate the... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

7. Shell Programming and Scripting

how to list files and execute an action?

I'm not sure how to word what I'm trying to do. I would like to: 1. Generate a list of files (easy to do ls -l > list.txt) 2. Carry out an action again each file in the list (not so easy to do) Like: List all files in /dir and then execute a move of each file individually. something... (6 Replies)
Discussion started by: bbbngowc
6 Replies

8. Shell Programming and Scripting

I do I execute several files in a directory

I have a directory with several files with commands inside: file1 file2 file3 ... file n I want to make a script that will execute the commands in this files one by one and move the files to another directory. When there is no more files in the directory the script ends. Can you... (2 Replies)
Discussion started by: nagomes
2 Replies

9. Linux

I need help getting my tar.gz files to execute

I am having trouble getting my Tar.gz file to execute. I do the following tar -zxvf firefox-2.0.0.1.tar.gz at the terminal once installed I can not get the firefox Icon or bin to execute. I do not know how to configure the path to get it to work. It places the folder under the /root/usr/local/bin.... (6 Replies)
Discussion started by: pgoble
6 Replies

10. UNIX for Dummies Questions & Answers

Can crontab execute binary files?

Hello! I have an entry on my crontab. 10 00 * * * /bscsprod/bscs/prod/523/bin/tehcron.sh $ /bscsprod/bscs/prod/523/bin/vi tehcron.sh nohup teh -t -f > /dev/null & ~ ~ ~ ~ ~ ~ ~ ~ "tehcron.sh" 13 lines, 365 characters but executing the script from the... (5 Replies)
Discussion started by: Tris
5 Replies
Login or Register to Ask a Question

Featured Tech Videos