General discussion

Locked

Perl scripting question

By eric_7178 ·
To anyone who can help greetings,
I am a beginner at Unix shell scripting and am researching file processing.
The question I have can be done in c, however this defeats the purpose
my question is as follows:

use a command-line tool named "itstat" which will display the resolution of an image file and some other lines of information. It accepts a list of image files as arguments (i.e., "itstat FILE1 FILE2 ..."), and its output looks like this:
File: pet_mocap_comp_v1_tvfa_vd8.1713.jpg
Resolution: 720 x 547
Channels: 3
Channel Types: RGB without Alpha Bit
Depth: 8
You are in a directory with 50 randomly named and sized images, and you want to know quickly the resolution of each file. Write a script that takes no arguments and uses itstat to print the filename and resolution of each file in the current working directory in the following format:
g50_comp_v6_2kfa_lg10.0310.rla: 2048 x 1556 g50_comp_v6_2kfa_lg10.0610.rla: 2048 x 1556 g50_comp_v6_2kfa_lg10.0710.rla: 2048 x 1556


I cannot find the commandline tool "itstat" and therefore do not know how to create a proper script.

Any assistance will be greatly appreciated.

This conversation is currently closed to new comments.

9 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by dblanchard In reply to Perl scripting question

Googling the terms: 'itstat' and 'resolution' together didn't return any results. I think you must be following some internal documentation about an internally developed utility.

Find more details, and I'll try to help you out.

D

Collapse -

by eric_7178 In reply to Perl scripting question

Actually I tried the same thing.
Is there any way to create a perl script that will display the file names and resolutions of jpeg files in a linux environment?

Collapse -

by eric_7178 In reply to

thank you Jaqui
this is pointing me in the right direction.
Just out of curiosity, can you show me how the function would look in bash or c?

Collapse -

by Jaqui In reply to Perl scripting question

DESCRIPTION

These functions return information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file.

stat stats the file pointed to by file_name and fills in buf.

lstat is identical to stat, except in the case of a symbolic link, where the link itself is stat-ed, not the file that it refers to.

fstat is identical to stat, only the open file pointed to by filedes (as returned by open(2)) is stat-ed in place of file_name.

They all return a stat structure, which contains the following fields:
{tabled display won't look right: }
struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode device) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last change */
};


from:
http://www.die.net/doc/linux/man/man2/lstat.2.html

search results from google:
http://www.google.ca/linux?hl=en&q=lstat&btnG=Search&meta=

since I don't know perl, can't help with the script itself, but these should give some data for working with the lstat tool.

for the last poster.
which lib / module for perl will read /write image files?

I know that it can be done from bash, and by building a c or c++ program, but don't know perl to know if it can even read image files.

Collapse -

by eric_7178 In reply to Perl scripting question

thank you Jaqui
this is pointing me in the right direction.
Just out of curiosity, can you show me how the function would look in bash or c?

Collapse -

by Gary_W In reply to Perl scripting question

Given your requirements and the assumption that a program called itstat exists with that output, this will do the trick:

ls|while read line
do
resolution=`itstat|grep Resolution|cut -f2 -d:`
echo "$line: $resolution"
done

If you really need the format as you state (not really that readable for 50 entries) replace the echo line with this:

echo "$line: $resolution \c"

and add another "echo" at the very end.


Gary

Collapse -

by Martin Simons In reply to Perl scripting question

This sounds like some sort of class project with where you are to write a small perl script that uses a make believe command line utility. If this is the case the perl script would look like this:

open (CMD, "itstat |");

while (<CMD&gt {
if (m/File:/) {
s/^\s*File:\s*//;
$file = $_;
} elsif (m/Resolution:/) {
s/^\s*Resolution:\s*//;
$res = $_;
print $file, ": ", $res, "\n";
}

close(CMD);

This will accomplish what you need, without error checking, however, and because it is not using the FileHandle module or the my declaration it is not cleanly written.

Collapse -

by Martin Simons In reply to

This is, of course, perl as the title of your question implies. Also there should not be a smiley face there, but simply a ")". I must have accidentally inserted a ";" before the ")"

Collapse -

by Martin Simons In reply to

Also "itstat" should be replaced with "itstat `ls`" or "itstat *"

Back to Linux Forum
9 total posts (Page 1 of 1)  

Related Discussions

Related Forums