05-14-2007
Quote:
Originally Posted by emferrari
Hi
So, now my script is like this:
I repeat: Please put code inside CODE tags.
The following code doesn't give me any syntax errors, but I fixed the line breaks. Could that be your problem?
There are other issues with the script.
Quote:
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
You don't need to check for number of arguments, and if you give more than one file on the command line, this will cause the script to exit.
To exit from a script, use exit, not return; return is used to exit from functions and sourced scripts.
Quote:
# 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
There should be the same number of characters in both strings (or more in the first).
Quote your variables. That will fail if any filenames contain spaces.
Quote:
# 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?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I'm trying to delete lines from a large text file using VI.
Every line that I am wanting to delete start with 'S' - all others do not. (A list of users)
I've tried using * but doesn't seem to like it...any ideas...
Doesn't have to be VI - but I'm better with VI than sed/awk. (8 Replies)
Discussion started by: peter.herlihy
8 Replies
2. UNIX for Dummies Questions & Answers
when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)
Discussion started by: benu302000
3 Replies
3. UNIX for Dummies Questions & Answers
ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this
ls s*.dat > file_names.txt
can't figure out whats wrong with that line, any ideas?
thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies
4. UNIX for Dummies Questions & Answers
Hi All
Please excuse another straightforward question. When creating a tar archive from a directory I am attempting to use wildcards to eliminate certain filetypes (otherwise the archive gets too large). So I am looking for something along these lines.
tar -cf archive.tar * <minus all *.rst... (5 Replies)
Discussion started by: C3000
5 Replies
5. UNIX for Dummies Questions & Answers
find ./ -name t\* | sed "s@^./@@" > .filestobedeleted
j=$(wc -l < .filestobedeleted)
typeset -i cnt=0
typeset -i i=0
while read line
do
myarray=$line
((cnt = cnt + 1))
done < .filestobedeleted
while (1 Reply)
Discussion started by: aishu
1 Replies
6. Shell Programming and Scripting
Good evening All,
I have a perl script to pull out all occurrences of a files beginning with xx and ending in .p. I will then loop through all 1K files in a directory. I can grep for xx*.p files but it gives me the entire line. I wish to output to a single colum with only the hits found. ... (3 Replies)
Discussion started by: CammyD
3 Replies
7. UNIX for Dummies Questions & Answers
Im going insane trying to figure out what i consider a basic command on an SFTP server...
Im trying to download all files from a directory *done*
then remove all the files (and sometimes folders that contain files) i have downloaded on the remote directory...
the command i would normally... (2 Replies)
Discussion started by: mokachoka
2 Replies
8. UNIX for Advanced & Expert Users
These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all.
GNU/Linux Command-Line Tools Guide - Wildcards
GREP (1 Reply)
Discussion started by: cokedude
1 Replies
9. Shell Programming and Scripting
Does anyone know how I would go about inserting text at the beginning of a file with the file name containing a daily time stamp? Essentially I need to find the file name using a wild card, and then insert 3 lines of text - one of which is the processing date. Help please!? (1 Reply)
Discussion started by: cookie33
1 Replies
10. Shell Programming and Scripting
I have four files:
test
test2
test3
test4
I have this simple script:
#!/bin/bash
ls $1
Why does ./the_script.sh test* only list the first file, when a normal ls test* would list all four? What do I need to change in the script to be able to use wildcard? (12 Replies)
Discussion started by: KidCactus
12 Replies
CTPL(1) General Commands Manual CTPL(1)
NAME
ctpl - CTPL command-line template parsing tool
SYNOPSIS
ctpl [OPTION]... INPUTFILE...
DESCRIPTION
ctpl parses one or more INPUTFILE template against the provided environment and outputs the result.
OPTIONS
-h, --help
Prints the command line options.
-o, --output=FILE
Write output to FILE. If not provided, defaults to stdout.
-e, --env-file=ENVFILE
Add environment from ENVFILE. This option may appear more than once.
-c, --env-chunk=CHUNK
Add environment chunk CHUNK. This option may appear more than once.
-v, --verbose
Be verbose.
--version
Print the version information and exit.
--encoding=ENCODING
Specify the encoding of the input and output files. The default encoding is the system's one.
TEMPLATE AND ENVIRONMENT DESCRIPTION SYNTAX
For the documentation about the syntax of templates and environment descriptions, see the CTPL library's documentation.
REPORTING BUGS
Report CTPL bugs to ban@herbesfolles.org
CTPL home page: <http://ctpl.tuxfamily.org>
AUTHOR
Colomban Wendling (ban@herbesfolles.org)
COPYRIGHT
Copyright (C) 2010 Colomban Wendling. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
15 Apr 2010 CTPL(1)