ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Well, i downloaded largefile.tar.bz2 but is was corrupted. So i did a bzip2recover and now i have allot of small .tar files. way too many to handle at ones. (when trying to "tar xvf *" it says: too many arguments (translated)).
So i wanted to write a little program that handles the files one by one. But i ran into a little problem.
The files are like:
rec00001file.tar
rec00002file.tar
rec00003file.tar
etc etc etc
i thought of a while loop and add 1 on the file name every loop.
like:
tar xvf rec00001file.tar;
tar xvf rec00002file.tar;
tar xvf rec00003file.tar;
but here is my problem. the let statement has such an output:
00001 becomes 1
00493 becomes 493
etc
(TEST IT YOURSELVES IN A CONSOLE)
Code:
let x=00000004;echo $x
but i want 00024 to stay 00024, how can i change this? is there an extra command for the statement let to do this?
thnx,
bas nelissen
(i read something about $i, but dont understand it)
Code:
#!/bin/bash
#tar-multi-unpacker
#made by b.nelissen
#QUESTIONS:
echo "hello world"
echo "starting you unpacking"
echo "whats the variable number of your first unpack item?:"
echo " (like: 0001 is in this file: rec0001file.tar)"
read number
echo "I am using: $number"
echo ""
echo "whats the variable number of your last unpack item?:"
echo " (like: 0845 is in this file: rec0845file.tar)"
read numberhigh
echo "I am using: $numberhigh"
echo ""
echo "whats the filename called BEFORE the variable number?:"
echo " (like: rec is in this file: rec0845file.tar"
read befornumber
echo "I am using: $befornumber"
echo ""
echo "whats the filename called AFTER the variable number?:"
echo " (like: file.bz2 is in this file: rec0845file.tar"
echo " (its possible and mightbe easier to use a wildcard like: * )"
read afternumber
echo "I am using: $afternumber"
echo ""
echo "where do you want me to unpack it to?"
echo " (like: /home/bla/bla)"
echo " (keep it empty for unpacking in the same dir)"
read outputdir
echo ""
echo "this is gonna be my command:"
echo " tar xvf $befornumber$number$afternumber $outputdir"
echo "to cancel press: Ctrl-c"
sleep 10
#EXAMPLE
#while [ $number -le $numberhigh ];
#do echo $number;
#let number=$number+1;
#echo "";
#done
while [ $number -le $numberhigh ];
echo $number;
do tar xvf $befornumber$number$afternumber $outputdir;
let number=$number+1;
echo "";
done
Last edited by bglnelissen; 09-27-2005 at 04:08 PM.
#!/bin/bash
#
# Increment number to become part of file name.
#
for (( i=1; i<100; i++ ));do
filenum=`printf "%05d" $i`
fname=rec${filenum}file.tar
echo $fname
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.