Problem printing with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem printing with awk
# 15  
Old 11-27-2017
This is NOT the input to the desired post processing! And so does NOT explain what output you are getting. We can only guess from what RESULTS you post what went into e.g. the printf command.

WHAT is the output of e.g. ps axo cmd= --sort=-%cpu, serving as the input? Using former on my system will yield a very different result that on yours, so I can't compare.
# 16  
Old 11-27-2017
A simple ps (by Yoda) and sort should fill your requirement :
Code:
ps -eo "%c,%U,%C,%n" | sort -t"," -n -k 3,3

Change the values you want from ps, delimited by comma for additional info.

sort is what you want, not awk(s) and gnu sort extensions.
Check out sort examples, it's a powerful tool.

Regards
Peasant.
# 17  
Old 11-27-2017
the output for
Code:
ps axo cmd= --sort=-%cpu

is:

Code:
/init
/bin/bash
ps axo cmd= --sort=-%cpu

and for user:

Code:
root
Eskizoide
Eskizoide

And when i do printf it just prints everything on one column.
Thank you for your patience.
# 18  
Old 11-27-2017
That only seems to be one single column as, be it variables or substitutions, contain line feeds that fold the output back to the next line. In fact, printf will see only two items (with many lines and words each) that consume only the first two format specifiers "%10s %25s.
# 19  
Old 11-27-2017
in fact it doesnt consume any format from printf because printf doesnt detect what i give him like a string.

neither this:

Code:
STRING=$(ps axo cmd= --sort=-%cpu)
printf "%20s\n" "$STRING"


Last edited by Scott; 11-27-2017 at 11:55 AM.. Reason: Code tags
# 20  
Old 11-27-2017
A bit difficult to believe. For me it prints pages full of commands and their parameters.

man printf:
Quote:
In no case does a nonexistent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result.
Try to limit the field width like %20.20s.
What's your OS and shell versions?
# 21  
Old 11-27-2017
RudiC, thank you for your help, but i decided to take a different aproach to the problem and i think i've solved. Instead of printing lists into the table, i sorted processes and show only the pid, now with a for loop, i take each pid and show the attribute that i need for that pid. So instead of printing a list of all processes, im inserting each one with a loop, that way i dont have problems with printf recognizing a string.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

problem with printing out variable in awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: couldn't print out stored variable in awk 2. Relevant commands, code, scripts, algorithms: i have in a... (5 Replies)
Discussion started by: ymc1g11
5 Replies

2. Shell Programming and Scripting

Problem with printing

Hi, i am writing a script to generate a summary report for my data text file my data in my text file goes like this: MacOS:Mary Abraham:53.48:88:38 Windows in lala:Mary Abraham:22.30:23:22 lala in Windows:John Goodman:33.60:121:12 Hello world:Mr Tian:23.30:23:10 Windows in 31 days:John... (2 Replies)
Discussion started by: Cheranime
2 Replies

3. UNIX for Dummies Questions & Answers

Problem with formatted printing in AWK

Hi, I want to print 130 fileds using formatted printing in AWK. It looks like awk '{printf ("%7.2f%7.2f...%7.2\n",$1,$2,...,$130)}' inflie>oufile But it gives me an error: Word too long! Can you please help me with this? Is there another way to do this? (1 Reply)
Discussion started by: PHL
1 Replies

4. SCO

Problem with printing

Does anybody know how I can stop the system slewing pages when a spool file has finished printing. I need to set up a method where all users are printing to the same printer to produce labels. The problem is that when the first users file has been printed the pages are slewed and the label is not... (2 Replies)
Discussion started by: rongrout
2 Replies

5. HP-UX

Printing problem

I have scheduled to print a numerous of report in mid-night. But, I found that some reports have not been printed out. Then, I checked the file /var/spool/lp/log and found that all reports have been submitted to print queue. Could anyone tell me what can be done to ensure all print jobs can be... (2 Replies)
Discussion started by: alfredo
2 Replies

6. UNIX for Dummies Questions & Answers

Printing problem

Hello, Not sure where to begin on describing the issue; please try to understand that I am not very familiar with SCO UNIXWARE. I am a newbie... We have a SCO UNIXWARE version 7.4 when we restart the computer we are required to enter the command lpstart, without it; people cannot print. ... (1 Reply)
Discussion started by: Yorgy
1 Replies

7. UNIX for Dummies Questions & Answers

printing Problem

When I print a file from an application it never stops printing. Any ideas? (2 Replies)
Discussion started by: 744eagle
2 Replies

8. IP Networking

Printing Problem

I have a printer installed on sun solaris m/c sun os 5.8. It doesn't print more than 52 files i.e if a give lp *.txt and the curent folder contains more than 52 files then it doesn't print them but if print in batches , each containing 52 files then it prints them properly. How do i increase the... (3 Replies)
Discussion started by: kapilv
3 Replies

9. UNIX for Dummies Questions & Answers

printing problem

i can only print from unix when I am logged in as host. When any user logs in (even myself as a user who has root priviledges) I cannot print. Has anyone heard of this problem before and are there any troubleshooting tips out there. HELP......... (3 Replies)
Discussion started by: acarroll
3 Replies

10. UNIX for Dummies Questions & Answers

Problem with printing

Hi , Can somebody Please help me in finding out where I am going wrong. Suppose i have a file called r_wer which contains files. for ex : LMN20001 LMN20002 LMN20003 Now I want to print them. The way I am doing is $ for a in `cat '/r_wer'` > do > lp -d printername $a > done But... (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question