?
Solved

How to add a value to a file name

Posted on 2013-05-17
7
Medium Priority
?
305 Views
Last Modified: 2013-09-18
How do you add a value to a existing file name.  Have a FTP process that receives back a trackingID during the process and when the file is archived needs to be added to the file name before the extension.

For example,

outbound_33333_20130515.xml   need to add a value,

outbound_33333_20130515_H23344232.xml

The added value is stored in a string, called trackingID.

Thank you for the help
Brian
0
Comment
Question by:bje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39176116
#!/bin/bash
trackingID=outbound_33333_20130515.xml
echo ${trackingID/./_H23344232.}
0
 

Author Comment

by:bje
ID: 39176264
My apology ,  I am sending files via FTP and trying to change the file name so the tracking id is in the file name before the .xml when the file is move to a archive directory.

the command i am using is

mv $file ${archive_dir}/$file_${TrackingID}

Which gives me, outbound_20130517.xml_H23344232

would like to have

outbound_20130517_H23344232.xml

Thanks,
Brian
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 39176277
#!/bin/bash
file=outbound_20130517.xml
trackingID=H2334423
echo ${file/./_$trackingID.}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bje
ID: 39227431
Thank you.  this worked.


I am working on another script which uses a "cntr" to keep track of the files and moves them to a archive.

I used this command and not sure what I have wrong with my syntax.

current:
mv ${file_sent[cntr]} ${archive_dir}/${file_sent[cntr]}.${TrackingID}

tried:
mv ${file_sent[cntr]} ${archive_dir}/${file_sent[cntr]}/./_${TrackingID}.}

Thank you for the help
0
 

Author Comment

by:bje
ID: 39491671
Hello,

The solution works.  I have a question on how you would insert a field when the file has a period inbetween the values.

example

apa.out.name.txt

would like to but a date/time stamp after name

apa.out.name.20130913140010.txt

my file name comes out app.20130913140010.out.name.txt

Thanks,
BJE
0
 
LVL 84

Expert Comment

by:ozo
ID: 39491939
file=apa.out.name.txt
trackingID=20130913140010
echo ${file%.*}.$trackingID.${file##*.}
0
 

Author Comment

by:bje
ID: 39502649
Thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question