• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

Pulling data from a file to create a new file name

Hello,
I am using the third position of a file name to look up a name in a config file; to use in creating a new file name.

From script -- determined if it is the Dev server or production server and the config file .
hostname=`uname -n`
case $hostname
in
        DEVSERVER ) EDI_ROOT=/usr/gentran/edidev
                              . ./partnername.sh;;
        PRODSERVER ) EDI_ROOT=/usr/gentran/ediprod
                               . ./partnername.sh;;
        * ) exit 1;;
esac

Taking the third position of the file name (WSC_850_11111_22222_20111010.tsv),  to look up the name in the config file.  Then creating a new file name.  

It is not reading by config file.  Not sure what is incorrect with my sytnax.  Attached is my config file.

Using typeset -A partnername
partnername =([11111]=ABC Company            
      [22222]=XYZ Company)
(File is attached)

 WSC_850*.tsv ) cp $file $archive_dir
                        varpartner=`echo $file | cut -d "_" -f3`
                        echo $varpartner
                        name=${partnername[$varpartner]}
                        newpartnerfile=${name}_${DateTimeStamp}.tsv
                        cp $newpartnerfile $edireports;;

Thanks
BJE
partnername.sh
0
bje
Asked:
bje
  • 2
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Hi bje, this shouldn't be that difficult but I'm not completely understanding what you want exactly.

- From file name "WSC_850_11111_22222_20111010.tsv" you want the 3rd position, this is "11111", right?
- Then you want to use the "11111" to look into the config file and find "ABC Company"?
- And finally you want to use "ABC Company" to create a new file called "ABC Company_20111010.tsv"?

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Something like this:
varpartner=`echo WSC_850_11111_22222_20111010.tsv | cut -d"_" -f3`
name=`grep $varpartner parnername.txt | cut -d"=" -f3`
newpartnerfile="${name}_`date +'%Y%m%d%H%M%S'`.csv"

Open in new window


Note that if you really want "ABC Company" in your filename that the space character in the name could cause issues, you'd have to create or copy the new file like this:
cp "$newpartnerfile" $edireports

Open in new window

0
 
bjeAuthor Commented:
Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now