- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk help needed
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 03:22 PM
тАО09-07-2004 03:22 PM
I am trying to write a script that will stagger the output below 6 fields accross separated by white spaces then create a new line until all of stdout has been appended in this format to a file.
example of output to be formatted... (only the file names field are to be formatted).
[root@melhpux3] /home/beala01-> du -sk ./*
7 ./Navimon.cfg
651 ./RPGC.prn
5 ./agent.config
8 ./audit-hpux-10092003.sh
29 ./benstat-dc.pri
2 ./bin/
7 ./class-users.csv
0 ./crap.out
0 ./crap/
1 ./default
7467 ./emcgrab/
1525 ./emcgrab_HP-UX_v3.4_1.tar
59 ./fileset-state.doc
107 ./fileset.doc
17 ./jaf.etp
4 ./nportids
6 ./p143027b.src
71 ./passwd
1 ./payroll-users.csv
370 ./scripts/
35030 ./spancustom.tar
4170 ./spo740c.tar
1 ./stuff.txt
22 ./superb-users.csv
1 ./supero-users.csv
3 ./tmp/
1 ./wp-testing.txt
157 ./wp/
desired output...
[root@melhpux3] /home/beala01-> ls
.Xauthority RPGC.prn
.cshrc agent.config
.jpiu benstat-dc.pri
etc...
If there is some way to do this in awk, i would appreciate your help.
Thanks in advance :)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 05:18 PM
тАО09-07-2004 05:18 PM
Solutionls | awk '{printf "%s",$0 ; if (NR % 6) {printf "\t";} else {printf "\n"}} END {printf "\n"}'
Or, if you want it better looking, but only if your columns are not too wide:
ls | awk '{ printf "%-15s",$0 ; if ((NR % 6) == 0) { printf "\n";}} END {printf "\n"}'
You can alter the columnwidth in the printf here, and the number of columns is the 6, used with the modulo sign (%).
(Of course it can be shorter, for instance replace printf "\n" with print ""..)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 05:20 PM
тАО09-07-2004 05:20 PM
Re: awk help needed
To get at more behaviour of ls with du then,
du -a | awk '{ print $2 }' | sed -e 's/^\.\///;s/\/[^ ]*$//' | sort -u
ls will display file as,
1 3 5 7
2 4 6 8
the order may be changed depends up on the files count there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 05:23 PM
тАО09-07-2004 05:23 PM
Re: awk help needed
cat in.txt | awk -F / 'BEGIN {cnt=0} {cnt+=1; if (cnt < 6) {printf "%s ",$2;} else {cnt=0; printf "%s\n",$2;}} END {printf "\n"}'
HTH,
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 05:39 PM
тАО09-07-2004 05:39 PM
Re: awk help needed
Elmar & Peter, both your commands worked perfectly, and gave the exact output I required!!!
OMG... you have no idea how much pain you guys have saved me!
Muthukumar, I couldn't get your's to work imediatley, but I will fiddle with it a bit.
Thankyou all once again :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 06:15 PM
тАО09-07-2004 06:15 PM
Re: awk help needed
# whatever_command | pr -t -a -w78
-t: terminal output
-a: accross
-w78: output width
Many more options supported
Enjoy, Have FUN! H.Merijn [ who uses the right function for the job ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 06:44 PM
тАО09-07-2004 06:44 PM
Re: awk help needed
I hope you got the awk with king's reply there. But procura's command more good as,
ls | pr -d -c 6
it will give easily.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2004 09:14 PM
тАО09-07-2004 09:14 PM
Re: awk help needed
Look at this as explanation:
ptc27b08:/var/adm/syslog # ls | pr -t -d -c 6
OLDsyslog.l mail.log.2. mail.log.6. syslog.log syslog.log. syslog.log.
genlog.log mail.log.3. mail.log.7. syslog.log. syslog.log. syslog.log.
mail.log mail.log.4. mail.log.8. syslog.log. syslog.log. syslog.logS
mail.log.1. mail.log.5. mail.log.9. syslog.log. syslog.log.
ptc27b08:/var/adm/syslog # ls
OLDsyslog.log mail.log.1.gz mail.log.4.gz mail.log.7.gz syslog.log syslog.log.3.gz syslog.log.6.gz syslog.log.9.gz
genlog.log mail.log.2.gz mail.log.5.gz mail.log.8.gz syslog.log.1.gz syslog.log.4.gz syslog.log.7.gz syslog.logSAMTRM
mail.log mail.log.3.gz mail.log.6.gz mail.log.9.gz syslog.log.2.gz syslog.log.5.gz syslog.log.8.gz
ptc27b08:/var/adm/syslog #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2004 02:38 AM
тАО09-08-2004 02:38 AM
Re: awk help needed
I did not give a -# (like -2) argument, because the original statement is not clear enough to me. Neither is the general definition of columned output of ls. There is no `rule' on how many columns ls produces. It depends on -F, using colors, screen width, screen properties (man terminfo look at xmc-cookie-glitch) and many other factors.
if the output of command 'blah' gives you three columns, and you want to make 6 columns where only the last field of each line is reformatted, do
# blah | pr -2 -a -t
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2004 05:08 PM
тАО09-08-2004 05:08 PM
Re: awk help needed
6*(width + 1)