[Ilugc] shell script to search for a file

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Sun, 1 Apr 2012 19:43:05 +0530

On Sun, Apr 1, 2012 at 7:22 PM, Bharath Kumar
<bharath79in at rediffmail.com> wrote:

Hi ILUGC members,

Thanks for your valuable suggestion. I have modified the code in such a way 
that if I search for an open office file that has 'spaces' in the name, it 
will output the kind of file.

Essence of the code :

I will create a file in the name that was converted from space format to 
underscore format.
I will open the document file and save it in the format as per the extension.
This is only for open document file.

Code Snippet

#!/bin/bash
echo -e "Input the file that you want to search: c"
read input
find ~ -name ${input}
echo -e "Input the file that you want: c"
read input1
export input1=`echo $input1 | tr ' ' _ `
touch ${input1}
ooffice ${input1}
file ${input1}

I would like to know how to write 'if' condition for image, audio, video 
files etc.


Okay.

You can escape space with backslash.

Now to recognize image,


$ identify

To recognize audio and video

$ mplayer -frames 0 -identify foo.[avi|mp3] | grep Audio

This is much better than any other easier tool.

identify(1) is part of ImageMagick.

UNIX is an ocean. Be patient. I have been learning, learning and learning.

-Girish

Other related posts: