1748250 Members
3297 Online
108760 Solutions
New Discussion юеВ

Re: Scripting Help

 
Rene_17
Regular Advisor

Scripting Help

I need a script for following problem !

I need to find all files with .afi extention.
After that i must cut the extention .afi und run a command with the files without extention.

13 REPLIES 13
Rene_17
Regular Advisor

Re: Scripting Help

Script:

!/bin/sh
set -x
for f in *.afi
do
afena $f ~/tmp
done

I must cut the .afi extention that afena command works !

Regards,

rene
Simon Hargrave
Honored Contributor

Re: Scripting Help

!/bin/sh
set -x
for f in `ls *.afi | sed 's/\.afi$//'`
do
afena $f ~/tmp
done

the sed will strip trailing ".afi" from each file. This will also work for files with multiple "." eg file.1.afi etc
Franky_1
Respected Contributor

Re: Scripting Help

Hi Rene,

for i in `ls *.afi|awk -F. '{print $1}'`
do
afena $i
done

This should work

Regards

Franky
Don't worry be happy
Jean-Louis Phelix
Honored Contributor

Re: Scripting Help

Hi,

Just for your information, because previous posts works, it's sometimes useful to know about shell's capabilities. For example :

phelix> A=foo.abcd
phelix> echo $(basename $A .abcd)
foo
phelix> echo ${foo%%.abcd}
foo

Regards,

Jean-Louis
It works for me (┬й Bill McNAMARA ...)
Rene_17
Regular Advisor

Re: Scripting Help


On the console the commands works !

Command: for f in 'ls *.afi | sed 's/\.afi$//''

But in the Script it didn├В┬┤t work ?

Message:
+ afena ls t1.afi t2.afi | sed s/.afi$//

?????????????

Regards,

Re
Rene_17
Regular Advisor

Re: Scripting Help


On the console the commands works !

Command: for f in 'ls *.afi | sed 's/\.afi$//''

But in the Script it didn├В┬┤t work ?

Message:
+ afena ls t1.afi t2.afi | sed s/.afi$//

?????????????

Regards,

Re
Franky_1
Respected Contributor

Re: Scripting Help

Hi,

why don't you just use the "awk" solution?
Even works in the script

Regards

Franky
Don't worry be happy
Rene_17
Regular Advisor

Re: Scripting Help

I notized that there where special characters around the command !

Thanks for your Help !

I only have one question !

Descripe to me the several characters above:

", ',`├В┬┤

Regards

Re
Simon Hargrave
Honored Contributor

Re: Scripting Help

You have changed the quoting on the "not working version".

It should read: -

for f in `ls *.afi | sed 's/\.afi$//'`

however you are now using: -

for f in 'ls *.afi | sed 's/\.afi$//''

Not the difference in quotes. The very first and last quotes should be backquote ` (top-left of your keyboard).

The awk solution suggested above will also work, however it will not take into account filenames with more than one "." in.