Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

explain sed script 3

Status
Not open for further replies.

plumz

Programmer
Jul 30, 2003
3
US
sed 's/^M//' $FN_TOP/out_HH1P/$1 > $2
 
sed 's/^M//' $FN_TOP/out_HH1P/$1 > $2
Remove the 1st character if equal "M".
The input file name is the 1st shell argument ($1) and is in a directory named $FN_TOP/out_HH1P.
The ouput file is the 2nd argument and is in the current directory.
The shell variable FN_TOP must contains the name of a directory.

Hope This Help
PH.
 
The ^M is a control character, and the above script is not the ideal way to treat this, since its escape status isn't always readable. (E.g., on some systems that character cannot even be typed, it has to be killed/yanked from within an editor.)

Here are two more predictable solutions:

tr -d "\015" $FN_TOP/out_HH1P/$1 > $2

-or-

dos2unix $FN_TOP/out_HH1P/$1 $2

BTW, the ^M (octal 015) is the DOS carriage return character accompanying the new line character (octal 012) in DOS files. Other OS (E.g., Unix) don't need this extra character and it shows up as a control character.

Sean aka TimeTraveler


Visit
 
Perhaps the sed should have read...

sed 's/\^M$//' $FN_TOP/out_HH1P/$1 > $2

escape the "^" and use "$" to indicate "from the end of the line" in the regex.
 
Thanks you all for the input!
That helps me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top