Juicy
Juicy

Reputation: 12530

Remove trailing string

In a bash script I have the following command which removes the trailing \r\n from the last line of a file.

# Copy the new last line but remove trailing \r\n
tail -1 $TMPOUT | perl -p -i -e 's/\r\n$//' >>$TMPOUT.1

It's currently using Perl to trim the \r\n off, but the target system I'll need to run this on won't have Perl or any other scripts (uClinux/Busybox embedded device).

How can I achieve the same in 'pure' bash?

Upvotes: 0

Views: 122

Answers (2)

anubhava
anubhava

Reputation: 786291

This sed should work:

sed -i.bak -n $'$s/\r$//p' "$TMPOUT"

Upvotes: 2

Arnab Nandy
Arnab Nandy

Reputation: 6712

Use tr command then,

tail -1 $TMPOUT|tr -d '\r\n'

Upvotes: 1

Related Questions