Adding a variable to a column in Linux

geodavegeodave Arizona
edited December 2010 in Science & Tech
Hello everyone,

I'm trying to add a predefined variable to a column in a text file in Linux. For example:
awk '{ print $1+2.50 }' file1.txt > file2.txt
works fine if I hard code the number 2.50 in the awk program. How would I go about making the 2.50 value a variable that I can predefine before the awk statement in a shell script?

Any help or suggestions would be greatly appreciated!

geodave

Comments

  • ardichokeardichoke Icrontian
    edited November 2010
    DERP=2.50
    awk '{ print $1+$DERP }' file1.txt > file2.txt
    

    I assume you're doing this in a shell script?
  • geodavegeodave Arizona
    edited December 2010
    Thank you, ardichoke, and sorry for the tardy reply. Yes, I am doing this in a shell script, and it worked beautifully.

    geodave
Sign In or Register to comment.