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.
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
On Sun, Mar 25, 2012 at 10:02 PM, Bharath Kumar
<bhara...@rediffmail.com> wrote:
> 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 ??
>
Not sure what you are trying to achieve here. If you know the path to
the file and also the extension to find the type, what is the need of
using 'find' command?
> This is my code snippet :
>
> #!/bin/bash
> echo -e "Input the file that you want to search: c"
> read input
> find ~ -name ${input}
You should enclose the file name in quotes.
Thanks & Regards,
Guruprasad
--- On Sun, Mar 25, 2012 at 10:02 PM, Bharath Kumar
<bhara...@rediffmail.com> wrote:
| But if the file has a gap (like /path/name/Bharath Kumar Letter.pdf)
\--
Windows users usually give whitespaces in the filenames/directories.
You might want to rename your files, directories so the whitespaces
are replaced with underscore (_) or dot (.). Refer (for a start):
http://stackoverflow.com/questions/2709458/bash-script-to-replace-spaces-in-file-names
In *nix, filename extensions don't really matter, except for few
applications which use them. Please don't name filenames with
whitespaces.
SK
--
Shakthi Kannan
http://www.shakthimaan.com
> #!/bin/bash
> echo -e "Input the file that you want to search: c"
> read input
> find ~ -name ${input}
Use $"input" instead of ${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
Also, the inline commenting method is wrong. In bash, you use # for commenting.
> read input1
> file ${input1}| cut -d: -f 2
>
>
> Thanks,
> Bharathkumar A.V.
> _______________________________________________
> ILUGC Mailing List:
> http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
--
With Regards,
Mehul Ved
you can use the following bit and operate on $file_name
export file_name=`echo $input1 | tr ' ' _ `
$ echo $file_name
Untitled_Document_1
you can add more checks to know if it is file is a directory or file and
process appropriately
-Satya
Determining the file type using the extension is the *wrong*. This is what
windows does - when an executable file has a folder like icon (in windows)
people will try to open it thinking they have created it and the virus file
executes - a trap. Anyway people struck up with Windows need to care for it.
Why don't you use "file" command instead of finding the extension? The
"file" command returns the MIME type of the file.
If the file is an mp3 file it says "Audio file with ID3 version 2.3.0,
contains: MPEG ADTS, layer III, v1, 160 kbps, 44.1 kHz, JntStereo".
Similarly for other type of files. If by chance you rename the mp3 file
with a .pdf extension or some thing else the "file" utility will provide
the correct type. "file" utility reads magic header in the file to
determine its type (not based on extension).
You may need to use extension only when the file is of type "ASCII English
text" - it may be a C or MATLAB program or any thing that is created with a
text editor (since all C files are text files).
Hope this helps.
But you have made a good beginning.
Keep going.
Some general observations:
1) Your shell scripting style is not typical. Learn from others and improve.
2) Even the file command is not always accurate.
3) Learn to look at return values of commands in the $? variable
4) You can escape spaces and other metacharacters in many ways. I normally
do a single pass rename of all files using mmv or even mv.
Example.
$ mmv -v "* *" '#1_#2'
Read mmv man page.
-Girish
On Sun, Mar 25, 2012 at 10:02 PM, Bharath Kumar
<bhara...@rediffmail.com> wrote:
--
G3 Tech
Networking appliance company
web: http://g3tech.in mail: gir...@g3tech.in
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.
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