Using the content of a file in the name of another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using the content of a file in the name of another
# 1  
Old 09-14-2006
Using the content of a file in the name of another

Hey there,

I have this issue: I have to use the contents of a file generated by the function:

#!/usr/bin/ksh
date '+%m %d %Y' |
{
read MONTH DAY YEAR
CEROD=0
DAY=`expr "$DAY" - 10`
case "$DAY" in
0)
MONTH=`expr "$MONTH" - 1`
CEROD=
CEROM=0
case "$MONTH" in
0)
MONTH=12
YEAR=`expr "$YEAR" - 1`
;;
esac
DAY=`cal $MONTH $YEAR | grep . | fmt -1 | tail -1`
esac
case "$DAY" in
-1)
MONTH=`expr "$MONTH" - 1`
CEROD=
CEROM=0
case $MONTH in
1|3|5|7|8|10|12)
DAY=30;;
2)
DAY=27;;
4|6|9|11)
DAY=29;;
esac
esac
.
.
.
.
case "$DAY" in
-6)
MONTH=`expr "$MONTH" - 1`
CEROD=
CEROM=0
case $MONTH in
1|3|5|7|8|10|12)
DAY=25;;
2)
DAY=22;;
4|6|9|11)
DAY=24;;
esac
esac
echo "$YEAR$CEROM$MONTH$CEROD$DAY" > fecha1.txt
}

And use it as a parameter of the name of a file Iīm transfering with this shell script :

/dconnect/cdunix/ndm/bin/cdpmgr -i /dconnect/cdunix/ndm/cfg/AFOIXE.UNIX/initparm
.cfg
set -v
NDMAPICFG=/dconnect/cdunix/ndm/cfg/cliapi/ndmapi.cfg
FECHA=`date +%Y%m%d`
export NDMAPICFG FECHA
/dconnect/cdunix/ndm/bin/ndmcli -x << EOJ
submit env_1104_1 process snode=INSCONS.UNIX startt=(`date +%D`,06:10 am)
step1 copy from (file=/dconnect/envios/20050808_AF_560_000.1104)
ckpt = 200k
compress = extended
to (file=/export/home/rec/CONTA/RECEPCION/$A_AF_560_000.1104
disp=rpl)
pend;
.
.
.
.
.

submit env_1104_5 process snode=INSCONS.UNIX startt=(`date +%D`,06:18 am)
step1
copy from (file=/dconnect/envios/20050814_AF_560_000.1104)
ckpt = 200k
compress = extended
to (file=/export/home/rec/CONTA/RECEPCION/20050814_AF_560_000.1104
disp=rpl)
pend;
EOJ


So long I havenīt figured out how to, so anyone could please help? Smilie
Thanks a lot!
# 2  
Old 09-15-2006
Lightbulb

get the value stored in the fetcha1.txt file and store it to a variable

x=`cat fetcha1.txt`

in the 2nd shell script use some keyword in place of the variable then use sed to find and replace the keyword you used.

for example you use <DATE> as keywords, the script would look like:

Code:
/dconnect/cdunix/ndm/bin/cdpmgr -i /dconnect/cdunix/ndm/cfg/AFOIXE.UNIX/initparm
.cfg
set -v
NDMAPICFG=/dconnect/cdunix/ndm/cfg/cliapi/ndmapi.cfg
FECHA=`date +%Y%m%d`
export NDMAPICFG FECHA
/dconnect/cdunix/ndm/bin/ndmcli -x << EOJ
submit env_1104_1 process snode=INSCONS.UNIX startt=(`date +%D`,06:10 am)
step1 copy from (file=/dconnect/envios/<DATE>_AF_560_000.1104)
ckpt = 200k
compress = extended
to (file=/export/home/rec/CONTA/RECEPCION/$A_AF_560_000.1104
disp=rpl)
pend;
.
.
.
.
.

submit env_1104_5 process snode=INSCONS.UNIX startt=(`date +%D`,06:18 am)
step1
copy from (file=/dconnect/envios/<DATE>_AF_560_000.1104)
ckpt = 200k
compress = extended
to (file=/export/home/rec/CONTA/RECEPCION/<DATE>_AF_560_000.1104
disp=rpl)
pend;
EOJ

use sed to replace <DATE> with the value you need:

Code:
sed "s/<DATE>/${x}/g" script.sh > script.tmp
mv script.tmp script.sh

execute the edited script. if you need to ensure permission into executable just use the chmod command.
# 3  
Old 09-18-2006
Bug

Thank you very much, your advise was 100% helpfull, you really got me out of trouble.

Cheers!

Thread Closed
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert content of file before the first occurrence of a line starts with a pattern in another file

Hi all, I'm new to scripting.. facing some problems while inserting content of a file into another file... I want to insert content of a file (file2) into file1, before first occurrence of "line starts with pattern" in file1 file1 ====== working on linux its unix world working on... (14 Replies)
Discussion started by: Jagadeesh Kumar
14 Replies

2. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

3. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

5. Shell Programming and Scripting

Facing issues with Content-Type:application/x-download Content-Disposition:attachment

I am in the process of developing a perl cgi page. I had succeeded in developing the page but there are few errors/issues with the page. description about cgi page: My CGI page retrieves all the file names from an directory and displays the files in drop down menu for downloading the... (5 Replies)
Discussion started by: scriptscript
5 Replies

6. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

7. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

8. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

9. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies
Login or Register to Ask a Question