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!

Formatting Variables

Status
Not open for further replies.
Aug 3, 2001
29
US
I am attempting to collect data and format one variable.

I have SYS + var1 (could be up to 15char) + var2 (could be up to 256char).

The var2 is a file name and can have from 1 to 256 chars.

I am putting this scenario together and inserting it at the beggining of each line to pass to another application to be worked on.

I've tried the printf command but am hitting a brick wall.
I must be doing something wrong.

Example of data

"SYS"
var1=RECKO214 could be up to 15char
var2=RECKITT-1.20021017155900-123456.txt


thanks

Len Turnbull
 
Len:

I had to put var2 in quotes. I'm sure awk is trying to interpret the dash as a negative sign:

# solaris 7
awk ' BEGIN { var1=RECKO214; var2="RECKITT-1.20021017155900-123456.txt" }
{
printf("%s%s%s\n", var1, var2, $0)
} '
 
This works if I am printing to the screen.
Example

var1=RECKFTP204 and print shows RECKFTP204 if I
echo "var1 > [$var1]"
it shows the [RECKFTP204 ]
but when I pass it to the line in the file it only shows
RECKFTP204 (one space) and no padding.
Am I doing something wrong or do I have to do something else ???


Thanks,

Len turnbull
 
Are we dealing with shell OR awk here?

Here's something to look at:
#------------------- a.ksh
#!/bin/ksh

typeset -L15 var1

var1="RECKFTP204"

nawk -v var1awk="${var1}" 'BEGIN { printf("[%s]\n", var1awk)}'
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top