You may find the file command of some use here it examines the contents of files looking for magic headers that help to determine the type of file.
for example:
The filetypes detected and reported tend to vary from unix platform to unix platform but could be of use in your script to detect "Zip archive" or "ISO-8859 text" for example.
Are you examining the contents of a directory looking for particular file types or are you looking at passed parameters to the script trying to determine the type. What is your final goal with this script?
Here is an example of a script that tries to identify the file type of all files passed on the command line:
You can see it fetches the output of the command file $file| cut -d: -f2 into the ft variable and the uses the switch statement to output different messages based on the strings returned from the [icode]file[/code] command.
that what I got but i dont know how to set to read from CL not from LS and how do you display a name out?
I am very confused. This thread is titled "Finding file extension on C Shell script" and you've told us your project only uses csh, but after seeing several examples showing you how to do some of the things you're trying to do using csh, you show us your bash script??? And, that script is missing several required newlines (or, in some cases, semicolons) and contains extraneous newlines in the middle of command names?
Furthermore, your description is confusing. Are you trying to display a filename and the filename extension in that name (if there is one); or are you trying to display a filename and its file type?
On a Windows system, the filename extension may determine what application will process that file. On a Linux or UNIX system, that is seldom true; filename extensions are more of a convention used to make it easy for humans to associate a file with its contents than for an application to be chosen by the operating system to process that file when it is opened.
Hello,
I have a shell script like the one below but cannot get it working:
#!/bin/bash
#$ -cwd
CHR=$2
# directories
ROOT_DIR=./
RESULTS_DIR=${ROOT_DIR}results/
# executable
SHAPEIT_EXEC=${ROOT_DIR}shapeit.v2.r727.linux.x64/shapeit.v2.r727.linux.x64
# parameters
THREAT=5... (1 Reply)
I have a directory that contains several files, out of which some files are have an extra extension for example
file1.new.new.new
file2.new.new.new
file3.new.new.new
file4.new.new.new
i want to write a shell script that rename all such file with only single extension like
file1.new... (7 Replies)
so I've made a shell script that downloads 6 files in succession from a given url, then deletes them. Now I want to time the script, and the average time it uses by running it ~100 times. My problem is tho, how do I store the time it takes for each run through of the script? I know time writes to... (3 Replies)
Hell Guys,
Being a newbie, I need some help in finding a certain string from a log file of thousands of lines (around 30K lines) and have the output in a separate file.
Below is the file output -
10.155.65.5 - - "POST... (15 Replies)
Hi.,
How to extract the extension of a file which are present in the directory?. In my script I tried something like:
echo abc_ss_222_54.txt | awk -F"" '{print $5}'
But I din't got .txt echoed in console. Pl. suggest a solution for this.
And also, for finding a specific... (1 Reply)
I searched the forum, but there was different type of rename.
Hello.
I have files in folder.
Like:
xxxxxxxx1.html
or
xxxxxxxx2.txt
or
xxxxxxxx3.tar.gz
and how to rename or change file extension case to
xxxxxxxx1.htm
or
xxxxxxx2.TXT
or (5 Replies)
Hi All
I have a csh shell script which should check if a given file is a zip file as below:
****************************************
#!/bin/csh -f
if ]; then
echo is a zip file
else
echo sorry not a zip file
endif
exit
****************************************
... (1 Reply)
Hey,
I'm having a problem finding out if a directory holds any files with a certain file extension, for example .txt.
I have tried: if (! -e "*.txt")
and I've tried: set FILES=`ls *`
echo "Found $FILES"
foreach FILE ($FILES)
if($FILE == "*.txt")
And neither of... (2 Replies)
hey,
im looking for a way of extending a string in shell script.
for example i have two strings "." and "abcd",
i need to extend the first string so that it is the same length as the second.
so "." and "abcd" becomes "...." and "abcd",
could someone shed light on how to do this ? thanks (4 Replies)
Rather new to unix, so please don't beat me!
I'm trying to get a list of files into a variable that I can use throughout the rest of the script. The challenge is that I need to exclude a certain extension from the list, and I'm having trouble with it. For example:
item_a
item_a.exe... (3 Replies)