Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I am trying to use the printf with awk to send some data to print.Here is the statement in my script:
echo "$i $state $q_date $project $title" | awk '{ printf "%-11s%-2s%-7s%-17s%-60s\n", $1, $2, $3, $4, $5 }' >>$tempdir/$Manager.msg
The problem is that I am trying align the fields - which is OK up to $4, but because the variable $title is several words so the utility only sees the first word in $title and prints it. I tried everything like \"$title\" '$title' ${title} nothing works...
can someone help! Please!! My script is overdue.I not sure if I had posted this problem here.
camin

By the time awk sees the line, the protecting quotes are already removed. But even if you protected the quotes with backslashes so that awk would receive "My First Report", awk would print "My for $5 because, by default, words are delimited with white space.
You can change your word separation to something else such as commas so that an awk field can contain spaces:
v3="My First Report"
echo $v1,$v2,$v3,$v4 | awk -F, '{print $3}'

![]() |
pkgadd - dont want to use...
|
How to undo partition/rec...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |