Using obase, help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using obase, help!
# 1  
Old 11-14-2008
Using obase, help!

I have a file that contains numbers...

Ex.
Code:
168446

I want to convert each number into binary and put the results into its own file.

I know below works
Code:
echo 'obase=2;1' | bc > file.txt

But my code cuts each char and use that as the number...as a variable or whatever and it doesn't work, code below suggestions? See $num is not working
Code:
  for i in 1 2 3 4 5 6
  do
    num=`cat time.txt | cut -c$i`
    echo 'obase=2;$num' | bc > ${i}binary.txt
  done

# 2  
Old 11-14-2008
$num does not get expanded when in single quotes, see if this works:
Code:
  echo "obase=2;$num" | bc > ${i}binary.txt

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question