Ignoring file name case and decrypting it.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignoring file name case and decrypting it.
# 1  
Old 12-14-2010
Ignoring file name case and decrypting it.

Dear Friends,

I want to decrypt 2 different file types in a folder (ZIP files and GPG files).
Each file type need different decryption syntex.
Hence, the script should identify file type and should act accordingly ignoring file name case i.e. upper or lower case.
Also, the extention can be in caps because of which the script should not be case sensitive.


E.g.
Following files I have in a folder which are to be decrypted

1) abc.zip (all lower case)
2) ABC.ZIP (all upper case)
3) aBc.zIp (combination case)
4) abc.gpg (gpg encription)
5) abc.GPG (gpg encription, combination case)

Manually we decript zip files by following syntex
unzip filename

Manually we decript zip files by following syntex
gpg filename




Please guide me to do the same
Thank you all in advance
Anushree
# 2  
Old 12-14-2010
Code:
find . -type f |while read file
do
  suffix=${file##*.}
  low=$(echo $suffix |tr '[A-Z]' '[a-z]')
  if [[ "$low" == "zip" ]]; then
      unzip $file
  fi
  if [[ "$low" == "gpg" ]]; then
      gpg $file
  fi
done

# 3  
Old 12-14-2010
Code:
for file in `ls | xargs`
do
extn=`echo "$file" | awk '{printf ("%-3s",$1)}' | tr '[A-Z]' '[a-z]'`
if [ "$extn" = "zip" ] ; then
    unzip "$file"
elif [ "$extn" = "gpg" ] ; then
     gpg "$file"
else
     echo "Unknown filetype"
fi
done

R0H0N
# 4  
Old 12-14-2010
How about :
Code:
decrypt(){
  case $1 in 
    *.[zZ][iI][pP]) unzip "$1" ;;
    *.[gG][pP][gG]) gpg "$1" ;;
  esac
}

decrypt abc.zIp

# 5  
Old 12-14-2010
#do zip
ZipFiles=`ls | grep -i .zip` > /dev/null
for File in $ZipFiles
do
printf "\nUnpacking: ${File}."
unzip "$File"
done

#do gpg
GPGFiles=`ls | grep -i .gpg` > /dev/null
for File in $GPGFiles
do
printf "\nUnpacking: ${File}."
gpg "$File"
done
# 6  
Old 12-14-2010
Using Scrutinizer's proposition, with recent version of bash:
Code:
decrypt(){
  case ${1,,} in 
    *.zip) unzip "$1" ;;
    *.gpg) gpg "$1" ;;
    *) echo "Unknown filetype" ;;
  esac
}

Man bash
Code:
${parameter^pattern}
${parameter^^pattern}
${parameter,pattern}
${parameter,,pattern}
       Case  modification.   This  expansion modifies the case of alphabetic characters in parameter.  The pattern is expanded to
       produce a pattern just as in pathname expansion.  The ^ operator converts lowercase letters matching pattern to uppercase;
       the  , operator converts matching uppercase letters to lowercase.  The ^^ and ,, expansions convert each matched character
       in the expanded value; the ^ and , expansions match and convert only the first character in the expanded value..  If  pat‐
       tern  is  omitted,  it  is treated like a ?, which matches every character.  if parameter is @ or *, the case modification
       operation is applied to each positional parameter in turn, and the expansion is the resultant list.  If  parameter  is  an
       array  variable  subscripted  with @ or *, the case modification operation is applied to each member of the array in turn,
       and the expansion is the resultant list.

# 7  
Old 12-14-2010
Hey Rdcwayx and Scrutinizer, it worked smoothly
also tried Rohon's solution, it worked after making certain changes in it...

Thank you for the quick guidance which was much needed.
God bless you all.
Anushree.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate lines after ignoring case and spaces between

Oracle Linux 6.5 $ cat someStrings.txt GRANT select on MANHPRD.S_PROD_INT TO OR_PHIL; GRANT select on MANHPRD.S_PROD_INT TO OR_PHIL; GRANT select on SCOTT.emp to JOHN; grant select on scott.emp to john; grant select on scott.dept to hr;If you ignore the case and the empty space between the... (6 Replies)
Discussion started by: kraljic
6 Replies

2. UNIX for Advanced & Expert Users

How To Find GPG Keys In Encrypted File With Out Decrypting it?

Hello All, Is there a way to determine how many public keys are embedded or used to encrypt in a GPG file with out decrypting the actual encrypted file. I know i can see the keys & email id's used when we decrypt it, but curious to find a command if any to know with out decrypting the actual file... (2 Replies)
Discussion started by: Ariean
2 Replies

3. Programming

Encrypting/Decrypting passwords

I know that simply encrypting and decrypting passwords in a script is as bad as storing them in plain text, but I've been searching for an answer to this for a few days now, and haven't found an answer that fits the problem I'm having. Here's the scenario. I'll give more details than I think may... (3 Replies)
Discussion started by: mdrisser
3 Replies

4. Shell Programming and Scripting

Shell Script for encrypting/decrypting text file

Hello, I am a newbie in Shell scripting. At the moment, I have a program written in C++ which gives an output file in text format. I would like to write a shell program which can take that output file and encrypt it and later if needed I want to decrypt it. Could someone please help or... (3 Replies)
Discussion started by: Tanin
3 Replies

5. Shell Programming and Scripting

ignoring case

in if clause , how 1 can ignore case (i.e. small or capital) ny suggestions? (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

6. Shell Programming and Scripting

sed ignoring case for search but respecting case for subtitute

Hi I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute": original becomes substitute Origninal becomes Substitute ORIGINAL becomes SUBSTITUTE I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies

7. Shell Programming and Scripting

Ignoring case in sed search

I am getting a parameter from a user and I need to use it to search and return the matching line numbers in a file. I am using this code: recordNumber="$(sed -n '/'"$entry"'/{ = d }' unixdb1.txt)" where $entry is the passed search parameter. The problem is I need to ignore the case. ... (3 Replies)
Discussion started by: snag49ers
3 Replies

8. Shell Programming and Scripting

decrypting a file using shell script

how do you go about doing this i have a shell script here below but i am not to sure on the process of decrytpting the file. #!/bin/csh # # set am = ‘abcdefghijklm' set am = ‘ABCDEFGHIJKLM' set nz = ‘nopqrstuvwxyz' set NZ = ‘NOPQRSTUVWXYZ' cat $argv | tr $am $AM | tr $NZ $nz | tr $nz $am... (1 Reply)
Discussion started by: master_6ez
1 Replies

9. Shell Programming and Scripting

Decrypting Unix file

Accidentally, I encrypted a file while saving it in vi editor. While saving I used :X and when asked for encryption key, I simply pressed ENTER key without any input. Now, I want to decrypt the file. I searched the forum, but unfortunately didn't get the proper solution. In one of the... (1 Reply)
Discussion started by: rkkiran
1 Replies

10. Shell Programming and Scripting

decrypting a file

Accidentally, I encrypted a file while saving it in vi editor. While saving I used :X and when asked for encryption key, I simply pressed ENTER key without any input. I searched the forum, but unfortunately didn't get the proper solution. In one of the threads it asked to visit a particular... (1 Reply)
Discussion started by: rkkiran
1 Replies
Login or Register to Ask a Question