开发者

Unable to remove carriage returns

Greetings!

I have been tasked to create a report off files we receive from our hardware suppliers. I need to grep these files for two fields 'Test_Version' and 'Model-Manufacture开发者_开发问答r' ; for each field, I need to capture their corresponding values.

In a previous post, I found help to create a basic report like so:

    find . -name "*.VER" -exec egrep -A 1 'Test_Version=|Model-Manufacturer:' {} ';' 

Model-Manufacturer:^M
R22-100^M
Test_Version=2.6.3^M
Model-Manufacturer:^M
R16-300^M
Test_Version=2.6.3^M

However, the data that's output is riddled with DOS carriage returns "^M". My boss wants "Model-Manufacturer" to show like "Test_Version" i.e

Model-Manufacturer:R22-100
Test_Version=2.6.3
Model-Manufacturer:R16-300
Test_Version=2.6.3

Using sed, I attempted to remove the "^M" characters for "Model-Manufacturer" but to no avail:

find . -name "*.VER" -exec egrep -A 1 'Test_Version=|Model-Manufacturer:' {} ';' | sed 's/Model-Manufacturer:^M//g'

This command has not effect. What am I missing here?


Give this a try:

sed '/Model-Manufacturer:/s/\r//g'

If you also have newlines and you want to combine the two lines into one, you can use one of the techniques shown in the answers to your previous question.


you can remove the carriage returns using dos2unix if you have it. Or using tr

tr -d '\r' < file


If you're using Bash as your shell, or creating the script in vi, you should be able to do:

sed -e 's/<Ctrl-V><Ctrl-M>//g'

to remove the CRs.

Ctrl-V (the keystroke on your keyboard) inserts the next keystroke literally, and Ctrl-M is carriage return.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜