How to store file name in a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to store file name in a variable?
# 1  
Old 08-06-2015
How to store file name in a variable?

Hi All,

Daily I am generating a file dfm_daily_file_

ex: dfm_daily_file_05072015 date will be changed daily.

Once the file is FTP it is deleted.

I have tried the below code to get the file name with any date and store it in a variable its not working.
Code:
#!/bin/ksh 
filename="dfm_daily_file_*.dat"

echo "Sending File $filename by FTP"

ftp_file "RTM_SERVER"  "$filename" 

if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
fi

rm -f $SRDS_LA/$filename

fin_normale $0

Please help me how to get the file name into a variable.

Thanks in advance.

Last edited by Scrutinizer; 08-06-2015 at 04:51 AM.. Reason: CODE tags
# 2  
Old 08-06-2015
Please use code tags as required by forum rules!

The * within the quotes will not be expanded. Is there just one file? Try filename=dfm_daily_file_*.dat, then. If there's more than one single file, use sth. like find, but you'll need to specify the target date anyhow
# 3  
Old 08-06-2015
You could also try a for loop.

Modifications to you setup:
Code:
#!/bin/ksh 

for filename in dfm_daily_file_*.dat
do

  echo "Sending File $filename by FTP"

  ftp_file "RTM_SERVER"  "$filename" 

  if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
  fi

  rm -f "$SRDS_LA/$filename"
done
fin_normale $0

It is just a suggestion for a couple of changes relative to your code. I do not know the validity of the rest of your code...
# 4  
Old 08-06-2015
Hi,

Just only one file.

I forgot to mention one thing this file dfm_daily_file_*.dat is not in the same diectory.
This file dfm_daily_file_*.dat in this directory $SRDS_LA.

file name and Directory name I am passing to ftp_file.

As per your suggestion I modified as

Code:
filename=dfm_daily_file_*.dat

echo "Sending File $filename by FTP"

ftp_file "RTM_SERVER"  "$filename" "$SRDS_LA"

if [ $? -ne 0 ]
  then
    echo "errror in sending file"
    fin_anormale $0
fi

rm -f $SRDS_LA/$filename

fin_normale $0

After executing this script the output is showing as

Code:
ficftp="dfm_daily_file_*.dat"
Sending File dfm_daily_file_*.dat by FTP

Is it taking the file?

Please help me.

Thanks.

Last edited by Scrutinizer; 08-06-2015 at 05:19 AM.. Reason: code tags
# 5  
Old 08-07-2015
Doesn't look like. What is "ficftp" and what is "filename"? Try assigning like filename=$SRDS_LA/dfm_daily_file_*.dat.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a value from a file and store in a variable?

Hi, I have a file service.xml which has following content: <?xml version="1.0" encoding="UTF-8"?> <Service Ver="2.31.13"/> I want to read the value of Ver (that is 2.31.13) and assign to a variable which i further use. Please help me in that. (3 Replies)
Discussion started by: laxmikant15
3 Replies

2. UNIX for Dummies Questions & Answers

Extract data from a file and store it in a variable

Hi , I have an file like below , cat input.txt 'Pattern2' => 'blahdalskdahdlahldahdlakhdlahdlkajdlkaadasdadadadadadadasda ajlalnalndklandlaksdlkaddd' 'Pattern2' => 'aohaonalkndlanldandlandklasnldnaldnak' ............ ........ ..... Here is what am trying to do , I want to grep for... (3 Replies)
Discussion started by: scott_cog
3 Replies

3. Shell Programming and Scripting

Extract a string from a file and store it in variable

Hi, I've a file ImageSizeDetails.txt with the following contents: Image Name: swncd 01.10.00.04 Created: Wed Jan 9 14:05:48 2013 Image Type: ARM Linux Multi-File Image (gzip compressed) Data Size: 7351011 Bytes = 7178.72 kB = 7.01 MB Load Address: 00008000 Entry Point: ... (6 Replies)
Discussion started by: Parameswaran
6 Replies

4. Shell Programming and Scripting

To store the file name o/p from find command in to a variable

Hi How to use a variable to store the filename of a file which was found by the 'find' command. can this be practical-->var = find . -name "filename.dat" Please help.. (1 Reply)
Discussion started by: ayyappaas
1 Replies

5. Shell Programming and Scripting

Read the contents of a file and store them in a variable

Hi Gurus, I am trying for a scenario where in I want to read the contents of a file line by line and then store them in variables. Below is the script: #!/bin/ksh while read line do id=`echo $line | cut -f1 -d |` name=`echo $line | cut -f2 -d |` echo $id ... (11 Replies)
Discussion started by: svajhala
11 Replies

6. Shell Programming and Scripting

capturing a file to store in a variable

I have a file in a windows directory the file is delivery to us like this 07210900.dat where 07210900 is the current date. If I want to store that file in a variable UpLoadFileName and rename, so I can Ftp later to a UNIX directory, I am doing this, is this correct? CDRemoteDir='cd... (0 Replies)
Discussion started by: rechever
0 Replies

7. UNIX for Dummies Questions & Answers

Read a file and store each value in a variable

Hi, How to read a file and put the values in a script. E.g. file1.txt 02/12/2009;t1;t2 The script should read this file and put these values in 3 different variables x1,x2,x3 which can be used further. Thanks Ashu (3 Replies)
Discussion started by: er_ashu
3 Replies

8. Shell Programming and Scripting

store the first line of a file in a variable

i have to store the files in a folder and assign a variable to the the files. (0 Replies)
Discussion started by: dineshr85
0 Replies

9. UNIX for Dummies Questions & Answers

Read and store each line of a file to a variable

Hi all, I'm quite new to unix and hope that someone can help me on this. I'm using csh. Below is what i intend to do. 1. I stored some data in a file. 2. I intend to read the file line by line and store each line of data into a variable, so that i can used it later. Anyone have any... (4 Replies)
Discussion started by: seijihiko
4 Replies

10. UNIX for Advanced & Expert Users

how to read each letter from file and store it in variable.

Dear friends, i am writing csh script i have one dat file containing following data.like this. 08FD3 03A26 000FA0 FFFF0 BBA0F 00000 00000 from the above file i want to read each letter and store it in one variable. how it is possible. please help (7 Replies)
Discussion started by: rajan_ka1
7 Replies
Login or Register to Ask a Question

Featured Tech Videos