Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Name Manipulation

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a file which is ftp-ed from a VMS server to my AIX box. Since it has the ";x" value on the end of the file name from VMS, my gpg encryption is failing ... it thinks that the ';' is a command line separator and then can't find the file to encrypt.

I've come up with the following:

Code:
#!/bin/ksh

rm -f tmp*

ls OLY* > tmp1
awk 'BEGIN{FS=OFS=";"}{print $1}' tmp1 > tmp2

This gives me the 'correct' file name in tmp2 (there is only one file in the directory so only the one file name in tmp1).

What I'm not able to figure out is how to do a cp in the .ksh script to copy the original file (name in tmp1) to the new file (name in tmp2).

Example:

File pulled from VMS is called abd_082505.dat;5 . After the script piece above runs, tmp1 contains abd_082505.dat;5 while tmp2 contains abd_082505.dat . I want to copy abd_082505.dat;5 to abd_082505.dat, effectively renaming the file my gpg routine can't handle to one that it can.

Thoughts/comments/suggestions greatfully acknowledged and appreciated.

Tnx.

Tom

"My mind is like a steel whatchamacallit ...
 
Code:
cp 'abd_082505.dat;5' abd_082505.dat


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Hi

No need to take out the modified value from the [tt]awk[/tt] script. Compose the full [tt]cp[/tt] command inside, then execute it :
Code:
ls OLY* | \
awk 'BEGIN { FS=";" } { system("cp \"" $0 "\" " $1) }'

Feherke.
 
No need to use awk at all:

Code:
#!/bin/ksh

f=OLY*

mv "${f}" "${f%;*}"

The % makes Korn shell trim off the matching suffix, in this case a semi-colon followed by anything. This presumes that OLY* will only match one file, the one that you're insterested in.



Annihilannic.
 
Thanks, all. After posting this I went back to debugging and figured out how to pull just the one file (daily) I need over without the ';x' value (for the record, I do NOT like VMS!!! :)) Script is working fine in testing, tomorrow morning when it runs from crontab at 0500 we'll know for sure.

Tips y'all provided are great - they'll go into my bag of tricks for the next time I need inspiration.

THANKS!!!!!

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top