Computing.Net > Forums > Unix > Printing with AWK Utility

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Printing with AWK Utility

Reply to Message Icon

Name: camin
Date: May 5, 2004 at 09:39:54 Pacific
OS: SunOS 5.8 Generic_108528
CPU/Ram: unknown
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: May 5, 2004 at 13:10:20 Pacific
Reply:

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}'


0

Response Number 2
Name: camin
Date: May 6, 2004 at 06:05:49 Pacific
Reply:

Hi Jim,

That helps! You are great! Thanks a million for your help, appreciated very much.
camin


0
Reply to Message Icon

Related Posts

See More


pkgadd - dont want to use... How to undo partition/rec...



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Printing with AWK Utility

please help me with awk, please www.computing.net/answers/unix/please-help-me-with-awk-please/3813.html

find the number of line with awk. www.computing.net/answers/unix/find-the-number-of-line-with-awk/4554.html

SCO Printing with Jetdirect Problems www.computing.net/answers/unix/sco-printing-with-jetdirect-problems/1388.html