|
Fantas
|
Fantas
|
i'm looking for a way to count extensions in a text file like 1.jpg 2.gif etc i know i would have to $read it and inc but i'm lost
|
|
|
|
schaefer31
|
schaefer31
|
It would help if you give the structure of the text file's contents.
|
|
|
|
Fantas
|
Fantas
|
ok 1.jpg 3.gif 1.png 2.mov
what i'm looking for is a way to set a variable then inc that variable
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
|
|
|
|
Fantas
|
Fantas
|
yeah but $lines returns all lines not just ones with the extensions
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
alias filterext {
if ($isfile($2-)) {
var %re = $+(/^\Q,$replacexcs($1,;,\E|\Q,\E,\E\\E\Q),\E$/)
filter -ffg $qt($2-) nul %re
echo -a * Found: $filtered
}
} /filterext <extensions> <file> <extensions> should be a list of extensions you want to match like *.mp3;*.mpg;*.etc
|
|
|
|
Joined: Dec 2002
Posts: 3,534
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,534 |
alias ext {
var %x = 1, %f = $$1
while (%x <= $lines%f)) {
if ($gettok($read(%f,%x),2,46)) inc $+(%,$v1)
inc %x
}
}
/ext <file>
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
There's a few problems with this script. 1) Setting %f to $$1 will not take into account files that have spaces in the name. Use $$1- instead. 2) $lines%f should be $lines(%f) 3) Calling $read without the 'n' flag will evaluate identifiers in the file. Also, that loop could be greatly sped up by setting $lines(%f) to a variable instead of calling it in each iteration of the loop: var %x = 1, %f = $$1-, %l = $lines(%f)
while (%x <= %l) {
...
}
|
|
|
|
Joined: Dec 2002
Posts: 3,534
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,534 |
Ahh good find, getting a little tired here. Cheers. 
|
|
|
|
Joined: Dec 2002
Posts: 3,534
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,534 |
alias ext {
var %n = ext
.fopen %n $$1-
if ($ferr) { .fclose %n | return }
if ($fopen(%n)) {
while (!$feof) {
if ($gettok($fread(%n),2,46)) { inc $+(%,$v1) }
}
.fclose %n
}
}
I think this might be a little faster than my $read post.
|
|
|
|
Fantas
|
Fantas
|
ok not quite sure i follow ya here %f is my text file? alias ext { var %x = 1, %f = $$1-, %l = $lines(%f) while (%x <= %l) { if ($gettok($read(%f,%x),2,46)) inc $+(%,$v1) inc %x } } so i type /ext .jpg pics.txt?
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
Mine is /filterext <extensions> <file>, Slade's is /ext <file>
|
|
|
|
Joined: Dec 2002
Posts: 3,534
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,534 |
Nope, type:
/ext <file>
Then it'd look like:
%png 1 %jpg 2 %bmp 30
Or something similar
|
|
|
|
Fantas
|
Fantas
|
Hixxys keeps returning 0 and /ext does nothing i made a file called it pics.txt in the file i put 1.jpg 2.gif 1.png 3.mov 1.wmf
none worked
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
How did you call my alias?
|
|
|
|
Joined: Sep 2005
Posts: 2,630
Hoopy frood
|
Hoopy frood
Joined: Sep 2005
Posts: 2,630 |
Silly mistake.. just remove the "^" character from my alias: alias filterext {
if ($isfile($2-)) {
var %re = $+(/\Q,$replacexcs($1,;,\E|\Q,\E,\E\\E\Q),\E$/)
filter -ffg $qt($2-) nul %re
echo -a * Found: $filtered
}
}
|
|
|
|
|