0

I am trying to read a line in a file which has '\' in it. But it is not showing in output, please help me what is the reason behind and how to read it.

Ex: File has this data:

abc
abc\def

but while loop took the second line as 'abcdef'

2
  • Can you post the code you have? Commented May 27, 2013 at 10:57
  • 1
    Can "\" sign be a special character? Commented May 27, 2013 at 10:58

2 Answers 2

2

You can use the -r option. E.g in bash:

while read -r l; do 
  echo "$f"; 
done < yourfile
0
0

\ (backslash ) is an escape character . If possible use abc\\def instead of abc\def

Or use -r in your shell script as mentioned in the SO thread

sh read command eats slashes in input?

1
  • I have used abc\\def instead of abc\def before. I think using '-r' is comfortable than our assumption. It's working with '-r'. Thank You.. Commented May 27, 2013 at 13:03

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.