![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script for deletion using wildcards | aishu | UNIX for Dummies Questions & Answers | 1 | 01-09-2008 05:37 PM |
| ls with wildcards | benu302000 | UNIX for Dummies Questions & Answers | 10 | 06-29-2005 01:53 PM |
| wildcards | benu302000 | UNIX for Dummies Questions & Answers | 3 | 06-29-2005 12:10 PM |
| Wildcards in VI | peter.herlihy | UNIX for Dummies Questions & Answers | 8 | 01-08-2002 04:27 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Use wildcards in a script
Hello
I have this script: #!/bin/ksh INPUTFILE=$1 TEMPFILE=$INPUTFILE.$$ OUTPUTFILE=$INPUTFILE.new # nr of arguments has to be 1 if [ $# -ne 1 ] then echo "\nUsage: $0 inputfile\n" return 1 fi # inputfile must exist and be readable if [ ! -r $1 ] then echo "\nInputfile $1 does not exist. Please enter a valid filename\n" return 1 fi echo "\nConvert File $INPUTFILE to $OUTPUTFILE" tr "ÖÓÒÕÔØöóòõôÄÁÀÃÂäáàãâåÜÚÙÛüúùûËÉÈÊëéèêÏÍÌÎïíìîÑñÇçªß¿" "OOOOOOoooooAAAAAaaaaaaUUUUuuuuEEEEeeeeIIIIiiiiNnCcaS?" < $INPUTFILE > $OUTPUTFILE # Change ß to SS # sed s/ß/SS/g $OUTPUTFILE > $TEMPFILE # mv $TEMPFILE $OUTPUTFILE echo "...ready\n" Which does conversion in file names to the US standard. It works for just one file at a time. I want to be able to do as the INPUTFILE a wildcard, for example: File_*.txt. Can someone help me on that? Regards, Eduardo Ferrari |
|
|||||
|
Quote:
Quote:
|
|
||||
|
Hi
So, now my script is like this: for file in "$@" do INPUTFILE=$file TEMPFILE=$INPUTFILE.$$ OUTPUTFILE=$INPUTFILE.new # nr of arguments has to be 1 if [ $# -ne 1 ] then echo "\nUsage: $0 inputfile\n" return 1 fi # inputfile must exist and be readable if [ ! -r $1 ] then echo "\nInputfile $file does not exist. Please enter a valid filename\n" return 1 fi echo "\nConvert File $INPUTFILE to $OUTPUTFILE" tr "ÃÃÃöôÃäãÃÃüÃëêÃïîê¿" "OOOOOOoooooAAAAAaaaaaaUUUUuuuuEEEEeeeeIIIIiiiiNnCcaS?" < $INPUTFILE > $OUTPUTFILE # Change à to SS # sed s/Ã/SS/g $OUTPUTFILE > $TEMPFILE # mv $TEMPFILE $OUTPUTFILE echo "...ready\n" done [mantas@IDBBANKMANTASDEV test]$ ./convertspecch.sh File*.txt ./convertspecch.sh[33]: syntax error: `newline' unexpected What's wrong? |
|
|||||
|
Please put code inside code tags.
Your loop is misplaced. When you split a command over several lines, don't forget to put the continuation character \ as the last character of lines to be continued. Code:
# nr of arguments has to be at least 1
if [ $# -lt 1 ]
then
echo "\nUsage: $0 inputfile(s)\n"
return 1
fi
for inputfile in "$@"
do
# inputfile must exist and be readable
if [ ! -r $inputfile ]
then
echo "\nInputfile $inputfile does not exist. Please enter a valid filename\n"
return 1
fi
outfile=$inputfile.new
echo "\nConvert File $inputfile to $outputfile"
tr "ÃÃÃöôÃäãÃÃüÃëêÃïîê¿" \
"OOOOOOoooooAAAAAaaaaaaUUUUuuuuEEEEeeeeIIIIiiiiNnCcaS?" \
< $inputfile >$outputfile
echo "...ready\n"
done
|
|
|||||
|
Quote:
Quote:
Quote:
Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|