The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
command help

In the command ls -la | awk '{print $5}' the command ouput for size is left to right I need it to be right to left
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
How do you mean? The fifth field is the size field... I don't get the bit about left to right and right to left...
Reply With Quote
  #3  
Old 07-23-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
Code:
ls -la | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'
Reply With Quote
  #4  
Old 07-23-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
Quote:
How do you mean? The fifth field is the size field... I don't get the bit about left to right and right to left...
I mean it printing the correct way with all the numbers lining up the way there supposed to. Test it you'll see what I mean.

Quote:
ls -la | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'
That was awsome Reborg it worked perfect.

If I may ask will you please explain it to me.

Chris
Reply With Quote
  #5  
Old 07-23-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
Quote:
ls -la | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'
Well that worked perfect until I put it into my app

What I am actually trying to do is
Code:
for f in $(<uploads); do 
    s=`echo "$PWD/$f"  | sed -e 's/^.*chris\.fileburst\.com/chris.fileburst.com/'`
    z=`ls -la "$f" | awk '{len = length($5) > len ? length($5) : len ; arr[NR] = $5 }END{ for ( a = 1; a < NR; a++ ) { printf "%"len"s\n" , arr[a]}}'`
    x=`ls -la "$f"| awk '{print $6,$7,$8}'`
    y=`md5sum "$f"| awk '{print $1}'`

echo -e "$s\t$z\t$x\t$y"
Now I know thats a long string and it was working with z=ls -la "$f" |awk '{print $5}' It just didn't print the size formatted left to right


Is there a way to incorporate what you gave me into that.

Last edited by reborg; 07-24-2006 at 04:31 AM. Reason: format the code
Reply With Quote
  #6  
Old 07-24-2006
Registered User
 

Join Date: Jul 2006
Posts: 36
If anyone has any ideas I still really need help with this output. All the ideas I have had only works partially.
Reply With Quote
  #7  
Old 07-24-2006
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,638
I don't have time to explain this code right now, but will post again later, I may be able to correct mistakes, but that depends on time.

Code:
#! /bin/awk -f
#
#  lineup.awk
#
BEGIN{
           maxf = 0
}
{
                sub ("^.*chris.fileburst.com", "chris.fileburst.com", $NF)
                # may need to adjust to the correct ouput for your system
                # keep values sequential
                     arr[NR,1] = $11
                     arr[NR,2] = $7
                     arr[NR,3] = $8
                     arr[NR,4] = $9
                     arr[NR,5] = $10
                     arr[NR,6] = $1
                # make sure you keep the i < value one greater that the 
                # number of entries in the array, same in the END block
                for ( i=1 ; i < 7; i++  ) {
                     if ( length(arr[NR, i]) > maxl[i] ) maxl[i] = length(arr[NR, i])
                }
}
END{
           for(x=1;x<=NR;x++){
                     for(y=1;y<7;y++){
                               if ( i == 2 ) {
                                   printf("%"maxl[y]"s ", arr[x,y])
                               }
                               else {
                                   printf("%-"maxl[y]"s ", arr[x,y])
                               }
                     }
                     printf("\n")
           }
}
The script becomes:

Code:
#!/bin/bash
while read file; do
      do echo $(md5sum $file) $(ls -l $PWD/$file)
done < uploads | ./lineup.awk
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0