You are not logged in.

#1 2012-08-26 14:25:15

darkbeanies
Member
Registered: 2009-01-14
Posts: 142

[solved]numbers from a text file as variables that I can do calcs on

Hi, I'm a bit stuck on this.  If I try to assign a variable as the result of a command output that parses a text file, and then try and use that variable later on eg.  bc it doesn't work.  The latest error gives me

(standard_in) 1: illegal character: ^M

So for example if I try to use awk to extract line 26, which looks like this:

50

and assign it to a variable "POINTS":

POINTS=$(cat blahblah.txt | awk "NR==26")
echo $POINTS 

produces the output "50" as expected,

but when I try and multiply the output by 2:

NEWVALUE=$(echo "$POINTS * 2" | bc)
echo $NEWVALUE

Gives the illegal character error above.  Strangely, if I put

POINTS=50

above the bc calculation line, it all works properly.

EDIT- FORGET IT

I think it's DOS format text crappy crap problem.  Nevermind.

Oh, and I'll mark this solved after I've had my cup of tea.  And after I've checked it really is solved of course...

Last edited by darkbeanies (2012-08-26 15:08:09)

Offline

#2 2012-08-26 14:42:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 18,898
Website

Re: [solved]numbers from a text file as variables that I can do calcs on

get dos2unix to convert the files first.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2012-08-26 15:07:39

darkbeanies
Member
Registered: 2009-01-14
Posts: 142

Re: [solved]numbers from a text file as variables that I can do calcs on

yup, dos2unix fixed all problems.  Hoorah!

Offline

Board footer

Powered by FluxBB