Passing a file name to a variable

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Passing a file name to a variable
# 1  
Old 10-20-2016
Oracle Passing a file name to a variable

Below is the command
Code:
mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '[a-z]' '[A-Z]'`.TXT

it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable .

After that i want to call a java program in the same shell script which will use this variable(i.e dynamic file name ) as parameter.

please let me know how to capture the dynamic file name present in the directory to a variable, so that i can pass that variable as a parameter in my java script which is called in the same shell script itself.

Please help asap.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-20-2016 at 11:12 AM.. Reason: Added CODE tags.
# 2  
Old 10-20-2016
The easiest way is to create the variable first and then use it in the mv command:
Code:
DATVAR=$(date "+%Y%m%d%H%M%S")
mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$DATVAR.TXT

Please be aware that I replaced the deprecated backticks by the $(...) "command substitution".
BTW, the date is all digits - so, why the tr?

A second way might be
Code:
mkfifo YYY
echo mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$(date "+%Y%m%d%H%M%S" | tee YYY).TXT & DATVAR="$(cat YYY)"
echo $DATVAR
20161020162732
rm YYY

of which I can't tell if its reliable and sensible enough for production systems.
# 3  
Old 10-20-2016
thanks Rudic for the quick reply.
its a existing code in production so i think i cannot remove tr command now, even though i am sure that removal of that won't create any issue.

but can we capture the the dynamic name including tr command by following the first
solution.

i mean can we write something like this
Code:
DATVAR=$(date "+%Y%m%d%H%M%S|`'tr '[a-z]' '[A-Z]'`")

mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$DATVAR .TXT

so i need to pass FTPYMNTE_$DATVAR.TXT as a parameter in java program right?
thanks in advance



Moderator's Comments:
Mod Comment AGAIN: Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-20-2016 at 12:29 PM.. Reason: Added CODE tags.
# 4  
Old 10-20-2016
Yes to both.
Why don't you assign the entire destination file name to a variable, then?
# 5  
Old 10-20-2016
did you mean something like this

Code:
DATVAR=$(FTPYMNTE_|date "+%Y%m%d%H%M%S|`'tr '[a-z]' '[A-Z]'`"|.TXT)

mv AP_FLEXCUBE_INTERFACE10.txt $DATVAR

please correct if any syntax error and the back ticks where it need to be placed



Moderator's Comments:
Mod Comment SERIOUSLY: Use CODE tags as required by forum rules!

Last edited by RudiC; 10-20-2016 at 12:52 PM.. Reason: Added CODE tags.
# 6  
Old 10-20-2016
Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!


Try
Code:
DATVAR=FTPYMNTE_$(date "+%Y%m%d%H%M%S" | tr '[a-z]' '[A-Z]').TXT

Pipes are used to connect processes by tying one's stdout to te next's stdin.

Strings are concatenated by writing them one after the other in the assignment statement. Should spaces exist within, enclose the entire assignment string in quotes.
# 7  
Old 10-20-2016
Thanks a lot for your reply. no spaces aren't used.SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

2. Shell Programming and Scripting

Passing variable from file to Oracle

cat a1 scott robert tom test script : #!/usr/bin/ksh for NAME in `cat a1` do VALUE=`sqlplus -silent "nobody/bobody01@testq" <<END set pagesize 0 feedback off verify off heading off echo off select username from dba_users where username=upper('$NAME'); END` if ; then echo... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

3. Shell Programming and Scripting

Passing variable from file to sql from script

Hi Friend, I have one file in which some number are mentioned and number of lines are vary every time And i need to pass that number to my sql command from script. Suppose i have file acc.txt 45456546456 45464564565 67854353454 67657612132 Number of records are vary every time.... (20 Replies)
Discussion started by: pallvi_mahajan
20 Replies

4. Shell Programming and Scripting

Passing variable as a file-Scripting Help

Hi Guys, i have a file where data is in the below format:: data1 data2 data3 data4 data4 data6 my script written as:: #!/bin/ksh cd $1 at now <<END sh $2 END Here i want to pass the values stored in the above file one by one till the end of line. Here if i am doing it as:: (2 Replies)
Discussion started by: Atp3530
2 Replies

5. Programming

PASSING PART OF FILE CONTENT TO VARIABLE

All, I have a log file containing lots of data now i want to extract all text between block below(names) without the title or end pattern but only names, ++++START++++ SCOTT TIGER HENRY PAUL JARED OTIENO OMOLLO JA NIGERIA ++++END++++ the names i want to return and store in a variable in... (1 Reply)
Discussion started by: Scott2000
1 Replies

6. Shell Programming and Scripting

passing file extension using external variable

Hi, How can I modify the FILETYPE command ? I want to provide the file extension, like txt, root .? Thanks, #!/bin/bash FROM=$1 TO=$2 FILETYPE=$3 ... (4 Replies)
Discussion started by: nrjrasaxena
4 Replies

7. Shell Programming and Scripting

passing variable to another file and replacing

Hi all, I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task? file1 code echo "Give... (3 Replies)
Discussion started by: Ananthdoss
3 Replies

8. Shell Programming and Scripting

Passing a variable to #BSUB -n in a LSF file

Hi There! I'm writing this LSF script to make it easier to send jobs to a cluster when varying certain parameters. At one point I'd like to do something like: set NPROC = 10 and later on call BSUB using something like: #BSUB -n $NPROC unfortunately for me, this throws an error: ... (4 Replies)
Discussion started by: lrayo
4 Replies

9. Shell Programming and Scripting

Passing output to variable instead of file

Hi, In normal shell scripting, how do you pass the output of a command to a variable, instead of a file and be able to use it later? The code is: #!/bin/bash who | cut -d" " -f1 > onlineusers Instead of passing the output of the above command to the file called 'onlineusers'... (1 Reply)
Discussion started by: Furqan_79
1 Replies

10. UNIX for Advanced & Expert Users

passing unix variable to sqlplus without a file name

Hi, I want to input unix variable to sqlplus.The following is working fine sqlplus username/password @dummy.sql param1 param2 << EOF create user $1 identified by $2; EOF But I dont want any file name to be passed,I just want to pass the parameter. Is there any way to that?? Thanks... (3 Replies)
Discussion started by: sakthi.abdullah
3 Replies
Login or Register to Ask a Question