Register
It is currently Wed Oct 22, 2014 9:47 pm

without decompress read extension inside and compare strings


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Oct 22, 2011 7:41 pm   

Joined: Sat Oct 22, 2011 6:31 pm
Posts: 4
Hi everyone

I'm trying to read several compressed files and compare the extension inside files.

Example:

Code:
namezip[0]=.tar.bz2
namezip[1]=.tar.gz
namezip[2]=.bz2
namezip[3]=.rar
namezip[4]=.gz
namezip[5]=.tar
namezip[6]=.tbz2
namezip[7]=.tgz
namezip[8]=.zip
namezip[9]=.Z
namezip[10]=.7z

for i in ${namezip[@]}
do
zcat $i | head
done



Want to to read the extension.

Example; .iso , .exe , .sh , .html , .txt , .mp3 , ...

If it's a text file ( with zcat there is no symbol ( only text )
Extract all text file

If .iso .exe .mp3 ( with zcat there is WEIRD symbol )
fkw|������T��T�9�9Y&34Y>Y\
do not extract

Is there a way to find them?

If we can't, can i compare first letter ( cut -c1 ) with something else..

Example:
Code:
letter=`echo {a..z}`
firstletter=`zcat $i | head | cut -c1`

if [ "$firstletter" = "${letter[@]}" ]
then
...
fi




Thanks for your help


Top
 Profile  
 PostPosted: Sun Oct 23, 2011 9:20 am   

Joined: Sat Oct 22, 2011 6:31 pm
Posts: 4
UP
UP

please guys :-O

Just write what you thinking..

I just need some idea.


Top
 Profile  
 PostPosted: Sun Oct 23, 2011 10:32 am   

Joined: Sat Oct 22, 2011 6:31 pm
Posts: 4
I have found something

I made a function to read inside.

Code:
#Variables
#File with extensions

namezip[0]=.tar.bz2
namezip[1]=.tar.gz
namezip[2]=.bz2
namezip[3]=.rar
namezip[4]=.gz
namezip[5]=.tar
namezip[6]=.tbz2
namezip[7]=.tgz
namezip[8]=.zip
namezip[9]=.Z
namezip[10]=.7z

#Function
#See inside

see () {
if [ -f $1 ] ; then
case $1 in
*.tar.gz) tar -ztf $1 ;;
*.gz) gunzip -l $1 ;;
*.tar) tar -tf $1 ;;
*.tbz2) tar -jtf $1 ;;
*.zip) unzip -l $1 ;;
*)    echo "'$1' is not a valid file" ;;
esac
else
echo   "'$1' is not valid file"
fi
}

#Code

for zip in *.gz
do
   see $zip
done


I just want to know if there is a simple way to see..


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP