0

I have a string in my configuration file say something like

 FirstParam|MyFile`date +"%Y%m%d"`.xml

My Script reads this line and splits values by pipe (e.g. "|") I want to convert second part i.e. MyFile`date +"%Y%m%d"`.xml to MyFile20141215.xml and pass it to another method. What is the best possible way for achieving this?

Thanks in advance.

2 Answers 2

1

The one quick and dirty I would use is (supposing a.txt is your file)

TodayFileName=`cut -d\| -f2 a.txt`
eval TodayFileName=$TodayFileName
Sign up to request clarification or add additional context in comments.

Comments

0

When you are concerned with security, you want to avoid evaluating 'external' commands. When the config file is just as secure as your script, eval is fine. When the config file can be changed by people with less rights, consider parsing the string with special fields:

$-> cat myfile
FirstParam|MyFileSED_YYYYMMDD.xml

$-> cat myParser
cat myfile | while IFS=\|; read firstfield secondfield; do
        echo Split into ${firstfield} en ${secondfield}
        echo "callingOtherMethodWith $(echo ${secondfield} |
           sed 's/SED_YYYYMMDD/'$(date +"%Y%m%d")'/')"
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.