Variable value not being fetched in the filename..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable value not being fetched in the filename..
# 1  
Old 05-31-2008
Error Variable value not being fetched in the filename..

Hi,

In the code below, the $DD1, $DD2, $MM1, $MM2 are not fetching the values. Can anybody tell me where have i made wrong.

Shift_date.sh is a script which gives the previous date if we give the current date in the format YYYYMMDD and +/- how many days past/future.. Like Shift_date.sh 20080531 -2 gives an output as 20080529.

At last echo $DD1 is giving the correct value. But i need to get that in Pockets_$MM1-$DD1_to_$MM2-$DD2_data.txt..
Is it because of meta characters being used? Please Help..

Code:
#!/bin/ksh

currweekday=`date '+%u'`

currdate=`date '+%Y%m%d'`

((n1 = currweekday + 7))
((n2 = currweekday + 1))

DD1=$(ksh Shift_date.sh $currdate -$n1 | cut -c7-8)
MM1=$(ksh Shift_date.sh $currdate -$n1 | cut -c5-6)
DD2=$(ksh Shift_date.sh $currdate -$n2 | cut -c7-8) 
MM2=$(ksh Shift_date.sh $currdate -$n2 | cut -c5-6)

echo Pockets_$MM1-$DD1_to_$MM2-$DD2_data.txt

echo $DD1

Thanks,
RRVARMA
# 2  
Old 05-31-2008
Error Continued from above problem..

Hi,

Also the above script is giving value only for $MM1 and $MM2, if i assign the values directly.. ie,

Code:
DD1=01
MM1=05
DD2=14
MM2=06

echo Pockets_$MM1-$DD1_to_$MM2-$DD2_data.txt

echo $DD1

I get a result like this..

Code:
Pockets_05-06-.txt
01

The problem is that i'm not supposed to change the file name format. It should include the meta characters as well.. Smilie
Please help..

Thanks,
RRVARMA
# 3  
Old 05-31-2008
Change
Quote:
echo Pockets_$MM1-$DD1_to_$MM2-$DD2_data.txt
to
Code:
echo Pockets_${MM1}-${DD1}_to_${MM2}-${DD2}_data.txt

# 4  
Old 06-01-2008
MySQL Thanks very much.. Problem solved..

Hi fpmurphy,

Thanks very much.. Its working now.. Smilie

Thanks,
RRVARMA
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting a row based on fetched value of column

Hi, I have a file which consists of two columns but the first one can be varying in length like 123456789 0abcd 123456789 0abcd 4015 0 0abcd 5000 0abcd I want to go through the file reading each line, count the number of characters in the first column and delete... (2 Replies)
Discussion started by: swasid
2 Replies

2. Shell Programming and Scripting

removing \n in PERL from the data fetched from db

Hi I am fetching data from table which contains SQL query like this into a variable $qry SELECT ABC, DEF WHERE (XYZ = 'Normalization' or ABC_TYPE = 'DEF') and lookup_port like 'ABAC%' My requirement is I need to fetch a where clause to a variable if ( $qry =~... (3 Replies)
Discussion started by: gvk25
3 Replies

3. Shell Programming and Scripting

Change the filename variable value

Hi guys, I have a variable where i am storing the filename (with full path). I just need the value before ".txt". But instead of getting the filename i am getting the contents of the filename. FileName=/appl/data/Input/US/Test.txt a=`awk -F"." '{print $1}' ${FileName}` echo $a... (3 Replies)
Discussion started by: mac4rfree
3 Replies

4. Shell Programming and Scripting

Set the last 4 letter in the filename as a variable

Hi all, I want to set the last 4 letter in the filename as a variable. For example, i have AB1234.txt file and i need to have last 4 letter as a variable. It should be like ; get last four letter set var = 1234 How can i write this in C shell?? Thanks, zibi (3 Replies)
Discussion started by: zibi
3 Replies

5. Shell Programming and Scripting

Inserting variable value into filename

Greetings, people of UNIX/Linux forums. I am having a problem with a script, where I am trying to create a new variable. The value of this variable would be dependent on the value in a couple other previous variables (all variables are 2-digit integers). Here is my code: #set the stations... (3 Replies)
Discussion started by: TheSMan5
3 Replies

6. UNIX for Dummies Questions & Answers

assingn a variable a filename and then reading it in

Im trying to set a filename to a variable and then read the file in using the variable but im getting a syntax error. any ideas? #!/bin/bash function scanFile() { while read $1 do echo $filename done } file1=report.log scanFile() $file1 (3 Replies)
Discussion started by: magnia
3 Replies

7. UNIX for Advanced & Expert Users

Issues while sending a mail having records fetched from SQL -all in UNIX

hi-I want to write a UNIX Script which will fetch records from Oracle database.I want to store these records in a file under fields like email address,name and the transaction_id and then fetch these records from the file and send the email to individual users with their transaction ID details. (4 Replies)
Discussion started by: DeepSalwan
4 Replies

8. Shell Programming and Scripting

variable used as filename

Hello, i'm fairly new to scripting, so please bear with me (I did try looking this up first, i figured it had to have been asked already). #!/bin/bash fileName=`date | sed -n 's/ /_/g p' | sed -n 's/^/Backup_/p' | sed -n 's/$/\.tar/p'`; #THIS SETS BACKUP_DATE echo $fileName #TEST OF VALUE ... (4 Replies)
Discussion started by: jzacsh
4 Replies

9. Shell Programming and Scripting

mv Filename variable to another filename

Anyone who can assist : I am trying to pass the group vairiable to a filename: rpt_tsavegrp=/export/legato/scripts/$group_savegrp_rpt.$dat It will not pass to variable. Anyone have any ideas what I am doing wrong here. Thanks # This script sends email that save group completed.... (3 Replies)
Discussion started by: gzs553
3 Replies

10. UNIX for Dummies Questions & Answers

AWK Filename as variable

Need some help. I need to load data into some Oracle tables and one of the pieces of data that I need to load is the filename. This filename is distinct every single time. Basically the last 6 characters will be different with no pattern. ex. testfile_041504_003567 To load the filename... (4 Replies)
Discussion started by: firkus
4 Replies
Login or Register to Ask a Question