[Ilugc] shell script to search for a file

Bharath Kumar bharath79in at rediffmail.com
Sun Apr 1 19:22:43 IST 2012


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. 

Thanks and Regards,
Bharathkumar A.V. 

On Sun, 25 Mar 2012 22:02:57 +0530  wrote
>Hi ILUGC members,
>

>
I have written a shell script to find out what type of file is the file I am searching for. If the resultant file name doesnt have any gap (like /path/name/Bharath_file.txt) I get the result correctly. But if the file has a gap (like /path/name/Bharath Kumar Letter.pdf) I get simply "ERROR". Is there any bug ?? Please help me resolve the bug please ??
>

>
This is my 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" // Comments : I will copy the file with the full name that I want
>
                                           //to find out what type of file it is 
>
read input1
>
file ${input1}| cut -d: -f 2
>

>

>
Thanks,
>
Bharathkumar A.V. 
>

FollowRediff Deal ho jaye!to get exciting offers in your city everyday.


More information about the ilugc mailing list