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
Simple Script mojoman Shell Programming and Scripting 6 05-12-2008 12:55 AM
simple script help ali560045 Shell Programming and Scripting 4 01-24-2008 01:24 AM
simple script ali560045 Shell Programming and Scripting 1 01-22-2008 12:41 AM
Simple Script Help Skunkie UNIX for Dummies Questions & Answers 4 10-02-2006 08:18 AM
simple script hedrict UNIX for Dummies Questions & Answers 4 02-23-2004 12:15 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-23-2005
moxxx68's Avatar
Registered User
 

Join Date: Mar 2004
Posts: 301
Question simple awk script...

hi everyone,
i have a script that I use regulary to look through my files and directories it works fine, but I would like to add a segment to the script to make the output more readable and userfriendly..
(i am not an expert on scripts so there is no comments or status exits as of yet..
)
#!/bin/bash
#.filer2
find $1 -type f -printf "%i\t%s %c %f\n" | egrep -v '(.date.*|foo|temp|file*)'| sort -n -r +1 | awk '($2 != 0)' | awk '{tot=i; i<=NR; i+=$2}END{print "Total="tot}{prin
t NR, $0}' | column -t

this is the script, the output is simply a listing plus a total of files greater than 0..



this is the directory tree
1 270199 2812 Sun Jan 23 16:13:33 2005 Gaining_skills.loc 14 270219 0 Sun Jan 23 16:13:33 2005 SElinux.loc
2 270190 2113 Sun Jan 23 16:13:33 2005 User_Concept.loc 15 270218 0 Sun Jan 23 16:13:33 2005 Managing_permissions.loc
3 270235 1608 Sun Jan 23 16:13:33 2005 Red_Hat.loc 16 270217 0 Sun Jan 23 16:13:33 2005 Hackers.loc
4 270236 1606 Sun Jan 23 16:13:33 2005 UNiX_FreeBSD.loc 17 270216 0 Sun Jan 23 16:13:33 2005 Filesystem_lockdown.loc
5 270234 1283 Sun Jan 23 16:13:33 2005 Linux_distributions.loc 18 270214 0 Sun Jan 23 16:13:33 2005 Linux_enabled.loc
6 270231 0 Sun Jan 23 16:13:33 2005 Tree_directories.loc 19 270213 0 Sun Jan 23 16:13:33 2005 File_heirarchy.loc
7 270230 0 Sun Jan 23 16:13:33 2005 Database_creation.loc 20 270212 0 Sun Jan 23 16:13:33 2005 Productive_linux.loc
8 270229 0 Sun Jan 23 16:13:33 2005 Basic_processing_commands.loc 21 270211 0 Sun Jan 23 16:13:33 2005 Free_linux.loc
9 270227 0 Sun Jan 23 16:13:33 2005 Partioning_HD.loc 22 270210 0 Sun Jan 23 16:13:33 2005 Basic_linux.loc
10 270226 0 Sun Jan 23 16:13:33 2005 Memory_Allocation.loc 23 270208 0 Sun Jan 23 16:13:33 2005 Mastering_networks.loc
11 270225 0 Sun Jan 23 16:13:33 2005 Full_performance.loc 24 270206 0 Sun Jan 23 16:13:33 2005 Learinig_security.loc
12 270223 0 Sun Jan 23 16:13:33 2005 Configuration_constructs.loc 25 270197 0 Sun Jan 23 16:13:33 2005 Using_Linux.loc
13 270220 0 Sun Jan 23 16:13:33 2005 Text_processing.loc 26 270189 0 Sun Jan 23 16:13:33 2005 Refined_usage.loc


that is the output of the whole directory recrusivly..
now this is the output of the script:
1 270199 2812 Sun Jan 23 16:13:33 2005 Gaining_skills.loc
2 270190 2113 Sun Jan 23 16:13:33 2005 User_Concept.loc
3 270235 1608 Sun Jan 23 16:13:33 2005 Red_Hat.loc
4 270236 1606 Sun Jan 23 16:13:33 2005 UNiX_FreeBSD.loc
5 270234 1283 Sun Jan 23 16:13:33 2005 Linux_distributions.loc
Total=8139


i would like to add title to each column .. like this
No. Inode Size Date Name
.................................................................................................... .....
1 270199 2812 Sun Jan 23 16:13:33 2005 Gaining_skills.loc
2 270190 2113 Sun Jan 23 16:13:33 2005 User_Concept.loc
3 270235 1608 Sun Jan 23 16:13:33 2005 Red_Hat.loc
4 270236 1606 Sun Jan 23 16:13:33 2005 UNiX_FreeBSD.loc
5 270234 1283 Sun Jan 23 16:13:33 2005 Linux_distributions.loc
Total=8139
i tried this but its not working too well..

#!/bin/bash
#.filer2
find $1 -type f -printf "%i\t%s %c %f\n" | egrep -v '(.date.*|foo|temp|file*)'| sort -n -r +1 | awk '($2 != 0)' | awk 'BEGIN{print $1, "No" $2, "Inode" $3, "Size" $7, "Date" $8, "Name\n""................................................................................\n"} {tot=i; i<=NR; i+=$2}END{print "Total="tot}{prin
t NR, $0}' | column -t

this does not seem to work the way that I am trying to get it to...
any feedback welcome
thanx moxxx68
__________________
moxxx68
http://www.estarinformado.com.ar/apicmaxmiel/bee-diez.gif
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-23-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
I took your data

1 270199 2812 Sun Jan 23 16:13:33 2005 Gaining_skills.loc
2 270190 2113 Sun Jan 23 16:13:33 2005 User_Concept.loc
3 270235 1608 Sun Jan 23 16:13:33 2005 Red_Hat.loc
4 270236 1606 Sun Jan 23 16:13:33 2005 UNiX_FreeBSD.loc
5 270234 1283 Sun Jan 23 16:13:33 2005 Linux_distributions.loc

into file2

and did some thing like this.

Code:
awk '
BEGIN { printf("%2s %6s %4s %-24s %s\n","No","Inode","Size","Date","Name");
        printf("-----------------------------------------------------------\n"); }
{ print $0 }
' file2
Reply With Quote
  #3 (permalink)  
Old 01-24-2005
moxxx68's Avatar
Registered User
 

Join Date: Mar 2004
Posts: 301
Cool

thanx i tried something along the lines but it did't quite work.. but I will give a try!
thanx for your feedback moxxx68
__________________
moxxx68
http://www.estarinformado.com.ar/apicmaxmiel/bee-diez.gif
Reply With Quote
  #4 (permalink)  
Old 01-24-2005
moxxx68's Avatar
Registered User
 

Join Date: Mar 2004
Posts: 301
this is what I tried amongst a few other combinations : no go!
can you give an example of the code?
here is what I have!
1 #!/bin/bash
2 #.filer2
3 find $1 -type f -printf "%i\t%s %c %f\n" | egrep -v '(.date.*|foo|temp|file*)'| sort -n -r +1 | awk '($2 != 0)' | awk '
4 BEGIN { printf("%2s %6s %4s %-24s %s\n","No","Inode","Size","Date","Name");
5 printf("-----------------------------------------------------------\n");}
6 {tot=i; i<=NR; i+=$2}END{print "Total="tot}{print NR, $0}' | column -t
edit:
this is what I keep getting anyway!
No Inode Size Date Name
-----------------------------------------------------------
1 270199 2812 Sun Jan 23 16:13:33 2005 Gaining_skills.loc
2 270190 2113 Sun Jan 23 16:13:33 2005 User_Concept.loc
3 270235 1608 Sun Jan 23 16:13:33 2005 Red_Hat.loc
4 270236 1606 Sun Jan 23 16:13:33 2005 UNiX_FreeBSD.loc
5 270234 1283 Sun Jan 23 16:13:33 2005 Linux_distributions.loc
Total=8139
__________________
moxxx68
http://www.estarinformado.com.ar/apicmaxmiel/bee-diez.gif
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:25 AM.


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

Content Relevant URLs by vBSEO 3.2.0