0

One line in a control file looks like this: 1039 ZA_BKPF_20170725103534.txt So using space as a delimiter, I am cutting and assigning the filename alone to a variable like below: file=echo "$line" | cut -d " " -f2

and then I use sed: sed -i 1d "$targetDir"/"$file"

but in the log I am getting the below error: I did an echo as well to confirm if the file exists. As you can see, the file exists. but sed says no such file or directory.

  • file=$'ZA_BKPF_20170725103534.txt\r'
  • echo '/u/applic/data/hdfs1/etl_grmacw/ACDW/source/ZA/ZA_BKPF_20170725103534.txt exists' /u/applic/data/hdfs1/etl_grmacw/ACDW/source/ZA/ZA_BKPF_20170725103534.txt exists
  • sed -i 1d $'/u/applic/data/hdfs1/etl_grmacw/ACDW/source/ZA/ZA_BKPF_20170725103534.txt\r' sed: can't read /u/applic/data/hdfs1/etl_grmacw/ACDW/source/ZA/ZA_BKPF_20170725103534.txt: No such file or directory

Is someone familiar with the $'string\r'. why is this happening to my variables. Is that the problem or something else? Can someone help me pls ! Thanks, Hari G

  • 2
    It looks as though your control file is in Windows format. The $'...' format is just being used for reporting purposes, to show that there is a return (0x0D) character in the variable. You can use tr to filter it out, – AFH Jul 26 '17 at 15:34
  • 1
    ... or use dos2unix on the input file to clean it up. – xenoid Jul 26 '17 at 20:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.