sed beginning of the line or the end of the line add the string

Yesterday, write a script that took two-thirds of the time of day, and most of the time is spent on the sed command, I'm sorry about today, not yesterday summed up the passage of time ah ~ ~ ~

file above fact, are still OK, yesterday to spend too much time, mainly because the file being processed is lead out with the results of Mysql extracted from the database, and then someone give me I'll just deal with, too brain damage = - I've been a little skeptical of so right result, there may be a problem windows and linux wrap, but because sed unfamiliar, has been engaged in sed. . . . . . . As all know (= -), window and linux line of the carriage return and so on, if you know, skip this paragraph, do not know, read the chant:

























Unix systems, the end of each row only "<wrap>", i.e., "\ n"; Windows system which, at the end of each line is "<line feed> <Enter>,", i.e., "\ n \ r". A direct consequence is that open files in Unix systems in Windows, then all the text will become a line; and Windows, the file is opened, then under Unix, at the end of each line might be more of a symbol ^ M.

Okay, so my question to the end of each line has a ^ M symbols in the file being processed, which usually is not apparent. You can use "cat -A test.file" command. So when I want to add characters end of the line, it is always the first to add a line and character will overwrite the original beginning of the line.

File conversion should look, there are two methods:
1. Command TEST.FILE the dos2unix
2. remove "\ r", command sed -i 's / \ r // ' test.file

Original link: https://www.cnblogs.com/aaronwxb/archive/2011/08/19/2145364.html

Guess you like

Origin www.cnblogs.com/soymilk2019/p/12600158.html