0

I have a script that uses this line of code:

system(['cat ' inputfile ' | tr -d ''\000'' | tr -d ''\015'' >& tempfile.txt']);

to go through a text file and delete some special characters and then put it into a temp file.

This line of code works in Matlab2012 but not in 2017 as it leads to this error:

tr: Illegal byte sequence
cat: stdout: Broken pipe

Does anyone know how to get around this issue? Thank you!

3
  • I’m not sure, but you might need to escape the backslash. MATLAB now recognizes octal constants, this could be the reason your code no longer works. I recommend that you remove the system call and just print out the composed string you pass to it. This will give you a hint as to what is wrong. Commented Oct 3, 2019 at 2:09
  • I got no error, using 2017b on ubuntu 16.04. I tried inputfile = which('ls.m'); and the tempfile.txt was created with no error. Commented Oct 3, 2019 at 6:56
  • Maybe inputfile contains spaces? Consider enclosing it in quotes. Commented Oct 3, 2019 at 7:36

1 Answer 1

1

The encoded format may not be supported by tr, try changing the locale (refer to https://unix.stackexchange.com/questions/141420/tr-complains-of-illegal-byte-sequence):

system(['cat ' inputfile  ' | LC_ALL="C" tr -d ''\000''''\015'' >& tempfile.txt']); 
Sign up to request clarification or add additional context in comments.

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.