You are not logged in.
Pages: 1
Hello,
I would like some help with a simple script.
I have say 10 text files (***.txt) in a directory. I want to make each *** into a subdirectory, insert the respective ***.txt file into that subdirectory as well as insert three other files into each subdirectory.
I then want to create a loop that will run a seperate script, which I already have, on each folder.
Thanks for any help
Offline
Welcome,
O.K. I'll just assume the ***.txt files are the only .txt files in the folder.
I won't write a full script but this snippet should give you an idea:
for f in *.txt; do
d=`basename $f .txt`
mkdir $d
mv $f [and other stuff] $d
otherscript $d; #you can do a second loop if you want to
done
Something like this should do what you want, depending on the other script you might have to cd to $d and then back.
Disclaimer: This is right out of my head, it is totally untested and might be completely wrong. If while experimenting with this something eats your box, it is not my fault!
Offline
Thank you very much...another question
I have a several folders with several files (all have ****-123.ars) in each folder that I want to run through gnuplot and plot. All files in each folder are to be plotted together.
some sort of loop that will go into each folder
some sort of loop that will go through each file and call this set of commands
gnuplot
set terminal postscript
set output file.ps
set logscale x
plot "****-123.ars" using 8:6 with line
or somehow use multiplot
I am new to both.
Thanks
Offline
something like this would list all files in each subdirectory together and allow you to execute a command on them (see man page for find):
find -iname "*-123.ars" -type f -exec blah blah
flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)
Offline
Furethermore, if you want to run "blah blah" only once and give it the found files as a list of arguments, the xargs(1) program will help:
find -iname "*-123.ars" -type f | xargs blah blah
Last edited by peets (2008-07-09 03:48:07)
Offline
find -iname "*-123.ars" -type f | xargs blah blah
xargs is very handy, but be careful when using it with the find command. If find returns too many results, xargs will generate a command that's too long for bash and it won't run the command.
Offline
thanks again for the help ... I will post my final script in a few.
Anyone know how to delete/remove the last 3 characters in a text file. They occur elsewhere in the file but I need them removed at the end.
Offline
head -c -3 textfile maybe?
Offline
that returns the first three lines of the file
Offline
tail?:P
For lack of better words: chair, never, toothbrush, really. Ohw, and fish!
Offline
If the last 3 char are on their own line, you can just delete the last line, for example with sed :
sed '$d' file
Otherwise if these 3 char are not alone, but are always the same string, for example "abc" you can do this:
sed '$s/abc//' file
The $ indicate that this substitution will be only made on the last line.
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
Hello,
I would like some help with a simple script.
I have say 10 text files (***.txt) in a directory. I want to make each *** into a subdirectory, insert the respective ***.txt file into that subdirectory as well as insert three other files into each subdirectory.
I then want to create a loop that will run a seperate script, which I already have, on each folder.
Thanks for any help
i think you need some basics:
http://www.gnu.org/software/bash/manual/bashref.html
http://wooledge.org:8000/BashGuide
http://wooledge.org:8000/BashFAQ
http://wooledge.org:8000/BashPitfalls
http://sed.sourceforge.net/sed1line.txt
http://student.northpark.edu/pemente/awk/awk1line.txt
Offline
jnwebb wrote:Hello,
I would like some help with a simple script.
I have say 10 text files (***.txt) in a directory. I want to make each *** into a subdirectory, insert the respective ***.txt file into that subdirectory as well as insert three other files into each subdirectory.
I then want to create a loop that will run a seperate script, which I already have, on each folder.
Thanks for any help
i think you need some basics:
http://www.gnu.org/software/bash/manual/bashref.html
http://wooledge.org:8000/BashGuide
http://wooledge.org:8000/BashFAQ
http://wooledge.org:8000/BashPitfalls
http://sed.sourceforge.net/sed1line.txt
http://student.northpark.edu/pemente/awk/awk1line.txt
Sorry for always being so propagandish, but I feel it's worthwile for your enjoyment and efficiency to mention that perl does all this and more. http://perldoc.perl.org
But, uh, "use the right tool for the right job". For the last 3 characters problem, briest gives the right solution. It works for me. Make sure you put the '-' in front of the 3.
Offline
But, uh, "use the right tool for the right job". For the last 3 characters problem, briest gives the right solution. It works for me. Make sure you put the '-' in front of the 3.
Waoh, I feel stupid now, I just read the answers quickly and saw that jnwebb said it didn't work so I did not look further and tried with other tools.
"head -c -3" works perfectly fine indeed, and it is a very easy and elegant solution. Sorry.
PS : I suppose my rank title is ironic and is here for making fun of me
Last edited by shining (2008-07-10 14:39:05)
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
thanks to all for suggestions and help... I am progressing...although slowly...in learning the basics. Your advice and help is both encouraging and helpful.
how can I list out the files in a folder into an array? I am doing the following:
ls *.filesIneed.txt > temp.txt
old_IFS=$IFS
IFS=$'/n'
ARRAY=($(cat temp.txt))
IFS=$old_IFS
But this seems to pump all of the files listed into the first entry of the ARRAY....any help?
Offline
Are you sure you need to do this? Usually, you can just do : for i in *; do [ something with $i ] ; done
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
yes...i will have a list of files (***.RS, and ***.CS) . I need to list them into two separate arrays and then use the data sets that are in them to do ration plots in gnuplot....
I need to be able set up a loop that will create a file with each line of the file having the following for each respective set of files)
"< paste FILE1.RS FILE1.CS using 1:($2:$4) with lines...etc" for gnuplot
Offline
Pages: 1