Hello, I was wondering if someone can assist me. I have a file that I download from a mainframe to a RedHat Linux 5.5 server, the file is delimited by control underscore characters and the record is terminated by a control M (carriage return). The problem I am having is with the control M character; in my shell script I read the file in and write out a new tweaked file. The new file that I create I am able to create the control underscore but I am not able create the control M on the file.... It just disappears from the file. (Just so people are aware.... I am aware that a control M is created in vi with a Ctrl-V Ctrl-M)
So far I have tried the following:
1) I set a variable to control M
Example:
The above writes out the values of Value1, Value2 and the Control K - That Works
3) I set a variable to control K then tried to replace the control K with control m using tr
Example:
Didn't work.... Control M disappears....
Now I have tried a bunch of other things but I am still not able to get a control M at the end of the record.... Let me be very clear the issue is getting the control M at the end of the record.... In my testing I am able to get a control M to appear in the middle of the record but that's not what I want. Does anyone have any ideas?
I suggest that you share your script's code (along with your operating system and shell version), a sample of the input data, a sample of the erroneous output that your script generates, and, finally, the desired output. Since non-graphic characters are crucial here, make sure to post octal/hex dumps of the input/output, so that there is no ambiguity about what we're seeing.
To generate a ^M in a shell script is trivial:
printf '\r'
If that doesn't work, I'm inclined to believe that the problem lies elsewhere.
On an unrelated note, your tr attempt does not convert from one control character to another. It selects a range of them and converts them to spaces, so, naturally, they "disappear".
First, it looks like you want a double qouted string, but the closing regular double quote at the end of the string and you have specified the opening double quote character rather than a regular double quote character that would be recognized by the shells to surround a string.
Second, you have ${...) instead of ${...} . You have to match the opening brace character with a closing brace character, not a closing parenthesis character.
Both of these will cause all three of the shell scripts you showed us to produce diagnostics like:
syntax error at line 2: `)' unexpected
or:
unexpected EOF while looking for matching `}'
unexpected end of file
depending on what shell you're using.
If you change the above line in all three of your scripts to: