Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I extract two numerical strings from a textfile and and want to combine them to create a new string. The new string will be a filename.

This is the textfile dates.dat:

378464,2015-01-31
1019348,2015-03-31
1019342,2015-03-31
1019347,2015-03-31
1019349,2015-05-11

My shell script:

while IFS=, read line
do
    IFS=',' read -r id date <<< "$line"
    filename="${date}-${id}.xml"
    echo $filename
done < "dates.dat"

All I see is 3784641-31 1019348-31 1019342-31 1019347-31 1019349-11. But I expect 2015-01-31-378464.xml etc.

share|improve this question
    
strange, tried here and looks ok (./script.sh -> 2015-01-31-378464.xml). Maybe some issue with formating dates.dat? –  AndreiR Aug 12 at 11:30
    
it works as expected on both ubuntu and solaris, I don't see the need for double read though. –  Archemar Aug 12 at 11:30
    
what shell are you using? –  jimmij Aug 12 at 11:33
    
Oh indeed, the problem was with the file. My colleague saved it on a Mac. –  MERose Aug 12 at 11:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.