Re: Scripting Help (586 Views)
Reply
Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 1 of 14 (586 Views)

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.

Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 2 of 14 (586 Views)

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
Honored Contributor
Simon Hargrave
Posts: 744
Registered: ‎06-15-1998
Message 3 of 14 (586 Views)

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
Respected Contributor
Franky_1
Posts: 322
Registered: ‎01-14-2001
Message 4 of 14 (586 Views)

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
Honored Contributor
Jean-Louis Phelix
Posts: 724
Registered: ‎10-07-2002
Message 5 of 14 (586 Views)

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 ...)
Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 6 of 14 (586 Views)

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
Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 7 of 14 (586 Views)

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
Respected Contributor
Franky_1
Posts: 322
Registered: ‎01-14-2001
Message 8 of 14 (586 Views)

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
Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 9 of 14 (586 Views)

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
Honored Contributor
Simon Hargrave
Posts: 744
Registered: ‎06-15-1998
Message 10 of 14 (586 Views)

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.
Honored Contributor
Jean-Luc Oudart
Posts: 1,461
Registered: ‎03-10-1998
Message 11 of 14 (586 Views)

Re: Scripting Help

Change the script to :

#!/bin/sh

set -x

for f in $(ls -C1 *.afi | sed "s/\.afi$//")
do
echo $f
done

Regards,
Jean-Luc
fiat lux
Regular Advisor
Rene_17
Posts: 137
Registered: ‎08-25-2003
Message 12 of 14 (586 Views)

Re: Scripting Help

I now understand the syntax.
Thanks for your help !

Rene
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 13 of 14 (586 Views)

Re: Scripting Help

You can do it easily with find command as,

-- test.ksh --
afena $1 ~/tmp
--------------

find -name "*.afi" -exec ksh test.ksh {} \;

Is afena a shell script function ?

You can also do as,

for FILE in $(ls *.afi|perl -pe 's/.afi$//)
do
echo $FILE
done
Easy to suggest when don't know about the problem!
Honored Contributor
Bharat Katkar
Posts: 2,309
Registered: ‎05-29-2003
Message 14 of 14 (586 Views)

Re: Scripting Help

Hi,
See if this works:

# find ./ -name *.afi | cut -d "." -f 1 | xargs

Regards,
You need to know a lot to actually know how little you know
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.