Help with rar


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with rar
# 1  
Old 08-31-2010
Help with rar

Hi UNIX experts,

I am stuck on a task due to ignorance with bash and all those commands.
I have thousand of split archive files on a folder called downloads

Each file is named as below:

0001.part1.rar
0001.part2.rar
0001.part3.rar
0002.part1.rar
0002.part2.rar
0003.par1.rar
0003.part2.rar
0003.part3.rar

I would like to extract them and get the main file which is a .DAT file
Problem is once I extract 0001.part1.rar through part3 another archive comes out with files name:

name.001
name.002
name.003
etc.

This is what I want to do:

1. Read the files on downloads folder
2. Group the files with the same prefix (put them on a folder base on the prefix)
Example:

0001.part1.rar
0001.part2.rar
0001.part3.rar

should go to folder 0001

3. Go to folder 0001 and extract the files.
4. Do another extraction because after the first extraction files becomes file.001 etc. which is another rar archive.
5. Rename the .DAT folder base on the list of names from a text file.
6. move the .DAT file to a new directory outside of folder 0001
7. Delete folder 0001
8. Go to the next set of files.
e.g.
0002.part1.rar
0002.part2.rar
0002.part3.rar
9. Repeat steps 2-8 until all files are extracted.

Thanks,
# 2  
Old 08-31-2010
Not tested.

Code:
find . -name "*.rar" |while read LINE
do
  folder=${LINE%%.*}
  mkdir -p $folder
  mv  $LINE $folder
done

PWD=$(pwd)

ls -l |grep ^d |awk '{print $NF} |while read LINE
do
  cd $LINE
# Put  rar extract command here.
  mv *.DAT $PWD
  rm -rf $LINE
  cd $PWD
done

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 08-31-2010
Quote:
Originally Posted by rdcwayx
Not tested.

Code:
find . -name "*.rar" |while read LINE
do
  folder=${LINE%%.*}
  mkdir -p $folder
  mv  $LINE $folder
done

PWD=$(pwd)

ls -l |grep ^d |awk '{print $NF} |while read LINE
do
  cd $LINE
# Put  rar extract command here.
  mv *.DAT $PWD
  rm -rf $LINE
  cd $PWD
done


Dude Thanks for your time looking into this

I tried the first part of the script and got some issues:

Code:
#!/bin/bash

find . -name "*.rar" |while read LINE
do
  folder=${LINE%%.*}
  mkdir -p $folder
  mv $LINE $folder
done

Result:

Code:
mkdir: missing operand
mv: missing destination file operand after `./0806.part1.rar'
Try `mv --help' for more information.
mkdir: missing operand
Try `mkdir --help' for more information.
mv: missing destination file operand after `./0806.part8.rar'
Try `mv --help' for more information.
mkdir: missing operand
Try `mkdir --help' for more information.
mv: missing destination file operand after `./0806.part2.rar'
Try `mv --help' for more information.
mkdir: missing operand
Try `mkdir --help' for more information.
mv: missing destination file operand after `./0806.part6.rar'
Try `mv --help' for more information.
mkdir: missing operand
Try `mkdir --help' for more information.
mv: missing destination file operand after `./0806.part7.rar'
Try `mv --help' for more information.

It does create the folder but I am not just sure why it cannot find it.

Last edited by farneville; 08-31-2010 at 05:15 AM..
# 4  
Old 09-01-2010
Code:
#!/usr/bin/bash

DIR=/xxx/xxx
cd $DIR

ls *.rar |while read LINE
do
  folder=${LINE%.par*.rar}
  mkdir -p $folder
  mv $LINE $folder
done

sleep 60

ls -l |awk '/^d/ {print $NF}' |while read LINE
do
  cd $LINE
# Put  rar extract command here.
  mv *.DAT $DIR
  cd $DIR
  rm -rf $LINE
done


Last edited by rdcwayx; 09-03-2010 at 01:45 AM..
# 5  
Old 09-02-2010
Thanks upper part of code works..
Second part not working though..

can you explain what the code does?

ls -l |awk '/^d/ {print $NF}' |while read LINE
# 6  
Old 09-02-2010
Quote:
Originally Posted by farneville
Second part not working though..
Try nawk instead of awk if you're not on a linux system. Beyond that, my crystal ball's still down for maintenance -- what error messages is it printing?

Quote:
can you explain what the code does?

ls -l |awk '/^d/ {print $NF}' |while read LINE
feeds the output of ls -l through awk, which (I think) filters out anything but directories, and then feeds it into the while loop which reads them one at a time into LINE.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Rar files

hi unix expert is there any program in linux to compress files or directory with rar (.rar)? i am using centos 7 many thanks samad (1 Reply)
Discussion started by: abdossamad2003
1 Replies

2. UNIX for Dummies Questions & Answers

How To Split A File In Two Rar Parts?

I Am connected to Whatbox.ca Seed Box Via SSH!! i have a file named avicii.mp3. I Want to split it into two rar parts as Apart1.rar and Apart2.rar So That When i Download Both the parts to My PC And Extract Them They Come out As Whole Avicii.mp3. There is also one more problem!! When I Rar A... (18 Replies)
Discussion started by: anime12345
18 Replies

3. UNIX for Dummies Questions & Answers

Using a rar file on a suse linux

Hi, I have this file in .rar format and need to use it on a suse linux system. I have transfered the file into the system and tried to unpack it using unrar command but i got this l# unrar e Alarm.rar UNRAR 3.51 freeware Copyright (c) 1993-2005 Alexander Roshal ??? - the file header... (5 Replies)
Discussion started by: mena
5 Replies

4. Fedora

Problem installing rar and unrar

Good day all, I am trying to install rar and unrar on fedora 16. In terminal root, when I try to do : # cp rar unrar /bin I get the following error message: cp: cannot stat `rar': No such file or directory cp: cannot stat `unrar': No such file or directory can anyone please... (7 Replies)
Discussion started by: peter_071
7 Replies

5. UNIX for Dummies Questions & Answers

Unzip a .rar file

Hi, How to unzip a .rar file in unix. I tried unrar command but it doesnt work. Any help will be appreciated Thanks (10 Replies)
Discussion started by: irudayaraj
10 Replies

6. Solaris

Extract .rar format files in Solaris

Hi All, Is there way to extract the .rar format files in Solaris Thanks, Mani Muthu (3 Replies)
Discussion started by: k_manimuthu
3 Replies

7. Red Hat

How to open RAR files?

May be this is a newbie question but i want to know hoe to open the RAR file in linux? (1 Reply)
Discussion started by: ashok.g
1 Replies

8. UNIX for Dummies Questions & Answers

How can i open rar files

Is there a way to open rar files on linux i would really appretiate if u would help :) (2 Replies)
Discussion started by: abu_malek
2 Replies

9. UNIX for Dummies Questions & Answers

how to extract a .rar file

Hi ! I have a abc.rar file. I want to extract this file.. pls help. OS Details : SunOS papillon 5.10 Generic_127111-11 sun4us sparc FJSV,GPUZC-M (1 Reply)
Discussion started by: dashok.83
1 Replies

10. UNIX for Dummies Questions & Answers

extracting .rar files

Hi, Can someone throw light on opening a .rar file? thanks, sskb (5 Replies)
Discussion started by: sskb
5 Replies
Login or Register to Ask a Question