Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using shell variables in awk??? 1

Status
Not open for further replies.

RobJordan

MIS
Apr 3, 2001
296
US
This is from a k shell script.

echo " $LINE\c"|awk '{printf("%-20s",$0)}' # print menu item

As you can see, in the second line of code,
I am trying to make the statement dynamic
by replacing the hard coded 20 with a shell variable.

echo " $LINE\c"|awk '{printf("%-${MENU_ITEM_WIDTH}s",$0)}'

Anyone know the correct syntax for the line above?

Thanks in advance,

Robert

Robert G. Jordan

Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
I reckon you need to pass the variable to awk ie
echo " $LINE\c"|awk -v MIW=${MENU_ITEM_WIDTH} '{printf("%-MIWs",$0)}'
I didn't test it, though
DickieBird
[thumbsup2]
 
Thanks! I got it to work by adding double quotes
around the variable MIW.

echo " $LINE\c"|awk -v MIW=${MENU_ITEM_WIDTH} '{printf("%-"MIW"s",$0)}' Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top