0

I have multiple password protected files in a directory eg:

file123.dat
file456.dat
file789.dat etc

I will be writing a script in linux to extract them with their passwords. each file has its own filename as password how can i extract the names of the files and put them in the script? NOTE:the password are certain alphabets from the filename and not the entire filename I am using 7zip to extract the file. The script i am using now is :

#!/bin/bash
FILES=`ls *.zip | xargs -r`
for FILE in $FILES; do
PASSWD=`echo $FILE | awk '{print substr($0,1,2)}'`
`echo abc``echo $FILE | awk '{print       substr($0,5,2)}'`

7za X -p $PASSWD $Z_FILE //using 7zip to unzip
if [ $? = 0 ]; then # successful unzip
break
fi
done
done
Rahul sawant
  • 415
  • 3
  • 6
  • 13
  • 1
    Give us an example of how it's store that data into the files... – DontVoteMeDown Nov 05 '13 at 16:25
  • 1
    What do you extract with, zip, [bzip2](http://en.wikipedia.org/wiki/Bzip2) or [something else](http://en.wikipedia.org/wiki/List_of_archive_formats)? Also, what have you tried? – miku Nov 05 '13 at 16:25
  • possible duplicate of [Bash Script to Execute Command on All Files in Directory](http://stackoverflow.com/questions/10523415/bash-script-to-execute-command-on-all-files-in-directory) – Marc B Nov 05 '13 at 16:25

1 Answers1

0
#!/bin/bash
FILES=`ls *.dat | xargs -r`
for FILE in $FILES; do
    PASSWD=`echo $FILE | sed 's/.dat//'`
     ## extract file $FILE using password $PASSWD
done
Claudio
  • 10,614
  • 4
  • 31
  • 71