![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i check whether a file has extension? | sunday8 | Shell Programming and Scripting | 2 | 6 Days Ago 06:58 PM |
| how to unzip File which has no extension | thepurple | SUN Solaris | 13 | 11-29-2007 01:46 AM |
| Stripping out the extension of a file name | ramky79 | Shell Programming and Scripting | 2 | 12-27-2006 10:25 AM |
| Check file extension | mahalakshmi | Shell Programming and Scripting | 6 | 12-27-2006 09:15 AM |
| default extension of file | rujupriya | UNIX for Dummies Questions & Answers | 2 | 05-17-2006 07:49 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How to get file extension
Hi all,
I am writing a script to do some matching for the filename. Let say there are multiple files in a directory, the filename is like below test.88 test2.88 test.99 test2.99 test3.99 For different file extension, different action will be taken. For example test.88 and test2.88 files will be load into one database, whereas test.99, test2.99 and test3.99 will be load into another database. I tried to use the nawk to get the file extension like below but is not working. for filename in `ls -l` do nawk 'BEGIN { FS="." }; { print $2 }' $filename done The print $2 didn't print the 88 or 99 extension. It just return me an empty value. Does anyone know what is going wrong here. Thank you so much. BR, Shirley |
| Forum Sponsor | ||
|
|
|
|||
|
Unexpected end of file
Hi Reborg,
Here is my complete script. #!/bin/ksh DIR="/root/test/statbackup" # Checking whether the directory exist or not if [ -d "$DIR" ]; then cd $DIR else print "ERROR: Directory doest not exist!" fi for file in * ; do case $file in *.88) #LOAD the file into Test1 Database mysql -uroot -ptecnomen teststat<<EOFMYSQL LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE test1 FIELDS TERMINATED BY '|' IGNORE 1 LINES; ;; *.99) #LOAD the file into Test2 Database mysql -uroot -ptecnomen teststat<<EOFMYSQL LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE test2 FIELDS TERMINATED BY '|' IGNORE 1 LINES; ;; *) print "Usage: $file is not in correct format" ;; esac done #Remove all the statbackup file rm -r /root/test/statbackup/* After I execute the script, I get error "syntax error:unexpected end of file". I tried go into the script and the line that script complaint actually is not occur, meaning one line more than the maximum script line. I really dont know how to solve on this. Please advise. Thank you so much. BR, Shirley |
|
|||
|
Quote:
Put your code in code tags, and if possible, indent your code for readability. back to your script, you used HERE document, << EOFMYSQL, but you left out the closing pair. Code:
case .....
...
LOAD DATABASE ... <<EOFMYSQL
....
...
EOFMYSQL
..
;;
...
esac
|
|
|||
|
Same error still prompt out
Hi ghostdog74,
Thank you so much for your advise. The code become so messy and difficult to read after I copy it into here. So sorry about it. I added in the closing pair for EOFMYSQL and tried to execute the script. The same error still prompt out. Is it ok to load the data into databse by using Case statement? Tried to execute the script by sh -x statbackup.ksh, but it didnt show where is the error, just prompt "unexpected end of file". Please advise. Thank you so much. Br, Shirley |
|
|||
|
Script code
Hi ghostdog74,
Here is my code: Code:
#!/bin/ksh
DIR="/root/test/statbackup"
# Checking whether the directory exist or not
if [ -d "$DIR" ]; then
cd $DIR
else
print "ERROR: Directory doest not exist!"
fi
for file in * ; do
case $file in
*.88)
#LOAD the file into Test1 Database
mysql -uroot -ptest statbackup<<EOFMYSQL
LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE Test1 FIELDS TERMINATED BY '|'
IGNORE 1 LINES;
EOFMYSQL
;;
*.99)
#LOAD the file into Test2 Database
mysql -uroot -ptest statbackup<<EOFMYSQL
LOAD DATA LOCAL INFILE '$DIR/$file' INTO TABLE Test2 FIELDS TERMINATED BY '|'
IGNORE 1 LINES;
EOFMYSQL
;;
*)
print "Usage: $file is not in correct format"
;;
esac
done
#Remove all the files
rm -r /root/test/statbackup/*
Thank you so much. Br, Shirley Last edited by shirleyeow; 01-14-2008 at 07:41 PM. |
|||
| Google UNIX.COM |