Re: how to easily strip CR from end of a string in bash?
From: Ian Giblin (giblin_at_panix.com)
Date: 08/20/03
- Next message: Moshe Jacobson: "Re: Question about "file" command"
- Previous message: Dan: "Re: sed or awk?"
- In reply to: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Next in thread: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Reply: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Aug 2003 13:29:02 -0700
"Laurent Vogel" <lvl@club-internet.fr> wrote in message news:<3f438474$0$9625$7a628cd7@news.club-internet.fr>...
> Ian Giblin wrote:
> >
> > Please, what's the best way to strip just this CR from the end of the
> > string? If necessary we can assume that the tail of the string
> > contains an alphanumeric character before the unwanted CR.
>
> POSIX sed, one of:
> sed 's/[[:cntrl:]]$//'
> sed 's/[^[:print:]]$//'
> GNU sed:
> sed 's/\r$//'
>
> I believe Christ intended to reply to you when he wrote this in another
> thread:
> ----8<----Chris
> unix to dos:
> sed -e 's/$/\r/' unixfile.txt > dosfile.txt
>
> dos to unix:
> sed -e 's/.$//' dosfile.txt > unixfile.txt
Thanks; these work if I *know* it is a dosfile and just want to strip
the last character, but if I don't know, it may break the file. I
think I am using GNU sed here. String is a filename, typically .MP3 or
.OGG so I tried this:
ech0 "$line" | sed -e 's/[^[3Gg]]$//'
But it never gets any matches. The original version using .$ does work
but is dangerous. Is it not possible to specify a control character
like CR to sed?
Thanks, Ian.
- Next message: Moshe Jacobson: "Re: Question about "file" command"
- Previous message: Dan: "Re: sed or awk?"
- In reply to: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Next in thread: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Reply: Laurent Vogel: "Re: how to easily strip CR from end of a string in bash?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|