Remove Last Character of Line

Hi,

I need to put the single line contents of a file into a variable, but remove the last character, for example the file would have this sort of contents:

2;4;3;10;67;54;96;

And I want the variable to be:

2;4;3;10;67;54;96 (notice the last ";" has gone).

Unfortunately I can't just do a cut of characters 1-x as the string will fluctuate in length!

Thanks.

If you're using ksh, you can strip off the last character like this:
x=${x%?}

1 Like

This is a continuation of this post.

You can use this if you use ksh:

someVar=`awk '{ printf $2 ";" }' file`; someVar=${someVar%;}

-----
Oops, oh well same idea :slight_smile:

1 Like

with vi its possible

:%s/.$//g

this will delete every last char on each line.

1 Like

or how about sed. x=`echo $i|sed s/.$//`

1 Like