How to compare file name with a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare file name with a string
# 8  
Old 03-15-2010
Hi
I tried with this but I am getting some problem with file name.

Actually I am writing a script in which there would be some csv files in a particular directory. Suppose in directory there are two files ABC.csv and XYZ.csv. Now I want to load these two files to different database tables using SQL loader. Based on the file name I am passing the table name to SQL loader.
While running it I am gettng below errors:

Quote:
Source file:
the file is /APPS/TCODDEV/xxinfc/bin/test/
Navistar.csv_15032010073727.ctl

/APPS/TCODDEV/xxinfc/bin/test
11
Creating Control File:/APPS/TCODDEV/xxinfc/bin/test/_15032010074437.ctl
Created control file:/APPS/TCODDEV/xxinfc/bin/test/_15032010074437.ctl
calling sql loader
LRM-00116: syntax error at 'log' following '='

SQL*Loader: Release 8.0.6.3.0 - Production on Mon Mar 15 07:44:37 2010

(c) Copyright 1999 Oracle Corporation. All rights reserved.

SQL*Loader-100: Syntax error on command-line
**********************************************************************
************************ Bad file ************************************
cat: /APPS/TCODDEV/xxinfc/bin/test/../log/_15032010074437.bad: No such file or directory
**********************************************************************
************************ Log file *******************************
cat: /APPS/TCODDEV/xxinfc/bin/test/../log/_15032010074437.log: No such file or directory
the file is /APPS/TCODDEV/xxinfc/bin/test/Navistar.csv

/APPS/TCODDEV/xxinfc/bin/test
12
Creating Control File:/APPS/TCODDEV/xxinfc/bin/test/_15032010074437.ctl
Created control file:/APPS/TCODDEV/xxinfc/bin/test/_15032010074437.ctl
calling sql loader
LRM-00116: syntax error at 'log' following '='

SQL*Loader: Release 8.0.6.3.0 - Production on Mon Mar 15 07:44:37 2010

(c) Copyright 1999 Oracle Corporation. All rights reserved.

SQL*Loader-100: Syntax error on command-line
**********************************************************************
************************ Bad file ************************************
cat: /APPS/TCODDEV/xxinfc/bin/test/../log/_15032010074437.bad: No such file or directory
**********************************************************************
************************ Log file *******************************
cat: /APPS/TCODDEV/xxinfc/bin/test/../log/_15032010074437.log: No such file or directory
/APPS/TCODDEV/xxinfc/bin/XXHYBRID_FORECAST_LOAD
Program exited with status 1

Below is my script

Quote:
DATE=`date +%d%m%Y%H%M%S`

#v_data_file=${p_source_directory}/${p_source_file}

archieve_dir=${p_source_directory}/../archieve

#ls $p_source_directory/* >file_dir
for i in ${p_source_directory}/*
do
echo "the file is $i"

case "$i" in
*Nav*)
v_filename=${file##*/}
v_table_name="XXHYBRID_FORECAST_NAV";;
esac

echo "$v_file_name"
echo ${p_source_directory}

bad_file=${p_source_directory}/../log/${v_file_name}_${DATE}.bad
log_file=${p_source_directory}/../log/${v_file_name}_${DATE}.log
ctl_file=${p_source_directory}/${v_file_name}_${DATE}.ctl


v_seq_num=`sqlplus -s $p_login << EOF
set head off
select XXLOAD_TEMP_TBL_SEQ.nextval
from dual;
EOF`

echo $v_seq_num
echo "Creating Control File:$ctl_file"
cat > $ctl_file <<!
OPTIONS (errors=5000,SKIP=1)
LOAD DATA
CHARACTERSET ZHS16GBK
INFILE '$i'
REPLACE INTO TABLE '$v_table_name'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
plant "LTRIM(RTRIM(Smilielant))",
build_date "LTRIM(RTRIM(:build_date))",
reg "LTRIM(RTRIM(:reg))",
job "LTRIM(RTRIM(:job))",
order_num "LTRIM(RTRIM(Smilierder_num))",
qty "LTRIM(RTRIM(:qty))",
step "LTRIM(RTRIM(:step))",
customer "LTRIM(RTRIM(:customer))",
sfx "LTRIM(RTRIM(:sfx))",
mdl "LTRIM(RTRIM(:mdl))",
feature "LTRIM(RTRIM(:feature))",
cust_req "LTRIM(RTRIM(:cust_req))",
Orddte "LTRIM(RTRIM(:Orddte))",
acct "LTRIM(RTRIM(:acct))",
loading_date "to_char(SYSDATE,'YYYYMMDD')",
created_by "fnd_global.login_id",
creation_date "SYSDATE",
last_update_date "SYSDATE",
last_updated_by "fnd_global.login_id",
last_update_login "USERENV('SESSIONID')"
SCHEDULE_NUM "replace(:customer,' ','_')||'-'||to_char(SYSDATE,'MONYY')||'-'||$v_seq_num"
)
!
echo Created control file:$ctl_file
echo calling sql loader

sqlldr userid=$p_login control=$ctl_file data=$v_data_file log=$log_file bad=$bad_file

if [ $? -gt 2 ]
then
echo ERROR!! Fail to run sqlldr program. Check whether the data file $p_data_file exist.
exit 1
fi

echo '**********************************************************************'
echo '************************ Bad file ************************************'

cat $bad_file

echo '**********************************************************************'
echo '************************ Log file *******************************'
cat $log_file

#mv $v_data_file $archieve_dir

done
Please guide me in finding the error.

Thanks in advance
Vishalaksha
# 9  
Old 03-15-2010
A quick walk through, I found :
Code:
v_filename=${file##*/}

you have nowhere defined the var file

perhaps, it would be:
Code:
v_filename=${i##*/}

# 10  
Old 03-15-2010
ls -lrt | awk '{if($9 ~ /ABC/) print $9}'
# 11  
Old 03-16-2010
In the above script I have some statements like

Quote:
bad_file=${p_source_directory}/../log/${v_file_name}_${DATE}.bad
log_file=${p_source_directory}/../log/${v_file_name}_${DATE}.log
ctl_file=${p_source_directory}/${v_file_name}_${DATE}.ctl
I am getting output like

Quote:
/APPS/TCODDEV/xxinfc/bin/test/../log/_16032010003044.bad
/APPS/TCODDEV/xxinfc/bin/test/../log/_16032010003044.log
/APPS/TCODDEV/xxinfc/bin/test/_16032010003044.ctl
Here the value of ${v_file_name} is missing. I want to create bad file and log file in the log directory while ctl file in the same directory test. I have used test/../log/ for this purpose but it is not working properly.

Please suggest me the possible cause.

Thanks
Vishalaksha

Last edited by vishalaksha; 03-16-2010 at 04:17 AM..
# 12  
Old 03-16-2010
Have you this line in your script:
Code:
v_filename=${file##*/}

to:
Code:
v_filename=${i##*/}

as anchal_khare suggested?
# 13  
Old 03-16-2010
I already corrected this... there were some errors at othere places also which have been corrected now. After all these corrections I have created a new file with same code and it is working fine now. There might a problem of some special character in previous file along with these errors.

Now I need one more suggestion from you all to achieve the below condition.

Quote:
# I need a logic like for i in (${p_source_directory}/*Nav*.csv or ${p_source_directory}/*ABC*.csv or ${p_source_directory}/*XY*.csv )
do
echo "the file is $i"

case "$i" in
*Nav*)
v_filename=${file##*/}
v_table_name="XXHYBRID_FORECAST_NAV";;
esac

done
Can I put OR condition in above for loop?

Thanks in advance
Vishalaksha
# 14  
Old 03-16-2010
Something like this:
Code:
for i in ${p_source_directory}/*.csv
do
  echo "the file is $i"
  case "$i" in
    *Nav*) (do your stuff here with *Nav* files) ;;
    *ABC*) (do your stuff here with *ABC* files) ;;
    *XY*)  (do your stuff here with *XY* files) ;;
  esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Shell Programming and Scripting

Compare user string with and predefined file...

i am trying to write shell script how to write shell script which is ask for user id and password then compare both from two different file.. i have no idea how to compare with data present in file.. #!/bin/bash -e read -p "User ID: " first read -p "Password: " second if ;then echo... (3 Replies)
Discussion started by: niko420
3 Replies

3. UNIX for Dummies Questions & Answers

Search for string in a file then compare it with excel files entry

All, i have a file text.log: cover6 cover3 cover2 cover4 other file is abc.log as : 0 0 1 0 Then I have a excel file result.xls that contains: Name Path Pass cover2 cover3 cover6 cover4 (1 Reply)
Discussion started by: Anamika08
1 Replies

4. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Compare two string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

6. Post Here to Contact Site Administrators and Moderators

Want a tcl script to compare a string in a file ignoring white spaces

Hi , I want a tcl script to search a string ignoring whitespaces in a .log file . It should correctly match . The string are as follows "Output-Maps 1 1 0 0 0" 1 and Active Intermediate-Maps 0 0 0 ... (1 Reply)
Discussion started by: kulua
1 Replies

7. UNIX for Dummies Questions & Answers

Compare 2 files print the lines of file 2 that contain a string from file 1

Hello I am a new unix user, and I have a work related task to compare 2 files and print all of the lines in file 2 that contain a string from file 1 Note: the fields are in different columns in the files. I suspect the is a good use for awk? Thanks for your time & help File 1 123 232 W343... (6 Replies)
Discussion started by: KevinRidley
6 Replies

8. Shell Programming and Scripting

How to compare particular string, if it is equal put into a new file

Hi, I have a file (sample.txt) this file contains below text. ./au ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./po ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./xxsbx/11.5.0/java/src ./xxsbx/11.5.0/lib ./xxsel ./xxsel/11.5.0 ./xxsel/11.5.0/admin ./zfa ./zfa/11.5.0... (2 Replies)
Discussion started by: gagan4599
2 Replies

9. Shell Programming and Scripting

String Compare

Hi i have a bash script which calls a PHP script (comparison_cron.php). The php script prints the string "no_data_to_retrieve" without quotes. Why does the following bash script not leave the while loop? #!/bin/bash cronOutput=$(php /srv/www/vhosts/xyz/httpdocs/comparison_cron.php)... (2 Replies)
Discussion started by: kaphiphi
2 Replies

10. Shell Programming and Scripting

Compare String

Hi everybody. I have this comand "/usr/local/check_procs myprocess" which prints "OK: myprocess running" on my console if the process is running and "myprocess not running" if it is not. I am writing a bash script to check if the process is running but am getting an error. Here is my... (3 Replies)
Discussion started by: kanexxx
3 Replies
Login or Register to Ask a Question