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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HPUX shell script: how to trim the last character

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
in HPUX shell script language, how do I trim the last character of string? For example, i need to capture the value of the string, and at the end it has "^M" (some sort of windows CRLF. I need to trim it out.

$ID = "1213234^M"
i want to trim it to "1213234"

Thanks!
 
Does HP-UX have dos2unix or an equivalent (possibly dos2ux if Google is correct)? That will trim the ^M for you.
 
sed should do it ....

Not in front of a UNIX box, but

eg. echo "12345^M" |sed -e 's/^M$//'

think that will work, can check for you on Mon.

What you're saying is substitute (s) ^M at end of line ($) with nothing.

Or of you wanted to replace the ^M with say F ... s/^M/F/
If you have space whitespace after the ^M (space of tab) then you'll need ...

sed -e 's/^M[ ].*$//' (you need a space and a tab in the
[ ], eg [<space><tab>].

Martin
 
I agree with Ken.
The command you are looking for is named dos2ux in HP-UX.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top