simple awk script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple awk script...
# 1  
Old 01-24-2005
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
# 2  
Old 01-24-2005
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

# 3  
Old 01-24-2005
Tools

thanx i tried something along the lines but it did't quite work.. but I will give a try!
thanx for your feedback moxxx68
# 4  
Old 01-24-2005
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple awk use

Hi, I have a file such that: 40454,31,48,4,1304.967741935484,1 31708,25,48,4,1268.32,1 20900,64501,671,788,0.3240259840932699,0 20137,51358,834,743,0.3920908135051988,0 I want to replace the 6th column by "ones" if it is 1, and with "zeros" if it is 0. Thanks. (6 Replies)
Discussion started by: shekhar2010us
6 Replies

2. Shell Programming and Scripting

Simple awk script needed

but I'm stumped...please help I have a file like this....... 1000 1 34 1000 10 34 1000 11 35 1000 20 35 1000 21 36 1000 30 36 2000 1 34 2000 10 34 which I would like printed out as 40 lines 1000 1 34 1000 2 34 1000 3 34 1000 4 ... (2 Replies)
Discussion started by: garethsays
2 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

help with simple awk script

Hi, I just don't understand awk. I think I'm close here but can someone give me a hand to finish this little parsing routine ? the input file is formatted like this: District 2502110 Gsub 2384889 Gsub 1428180 District 2502220 Gsub 1466390 Gsub 1466389 Gsub 1466388 Gsub 1466386 Gsub... (4 Replies)
Discussion started by: fwellers
4 Replies

5. UNIX for Dummies Questions & Answers

Simple awk script for positional replacement in text?

I have a string of letters. (They happen to be DNA, not that it's relevant to the question.) For analysis purposes, I need to replace the information at some of the sites. I need to do this based on their position, not the information in that position. I also need to ignore differences at other... (10 Replies)
Discussion started by: JFS
10 Replies

6. Shell Programming and Scripting

Simple AWK script problem.

Hi all, I have set up a simple awk script to calculate the average of values that are printed out a number of times per second (the number of time the printing occurs varies). The data is of the format shown below: 1 4.43 1 3.65 1 2.45 2 7.65 2 8.23 2 5.65 3 4.65 3 6.21 .. .. 120... (4 Replies)
Discussion started by: omnomtac
4 Replies

7. Shell Programming and Scripting

simple awk

when I execute this awk stmt .. awk "/log_directory/ { print $5}" /opt/dba/oraadmin/tools/tmp_purge_op.log it's returning the whole line as .. IRMD118_LISTENER1 parameter "log_directory" set to /opt/oracle/10.2/network/log/ my expected output is : /opt/oracle/10.2/network/log what... (7 Replies)
Discussion started by: talashil
7 Replies

8. Shell Programming and Scripting

Help with a simple script using awk

I need a hand with this simple script, in Unix i have a variable called portal: $ echo $portal chu0 when i use awk this variable is not recognized. How can i make awk recognize and print the value of this variable, since the output is not shown i.e. awk ' BEGIN {printf("%4s\t%14s\n",... (3 Replies)
Discussion started by: alexcol
3 Replies

9. Shell Programming and Scripting

need help with simple awk/ksh script

I need help finding out why this script wont run. The chmod is okay, but i get an error saying that I need '&&' on line 5. (18 Replies)
Discussion started by: tefflox
18 Replies

10. Shell Programming and Scripting

Simple awk script question

Hi, I'm a total beginner at awk and hope someone can advise what I have done wrong in the following script: I have a file which (to simplify things) may be something like this Fred Smith and Sue Brown Joe Jones and Jane Watts Sally Green and Jim O? Connor Freda O? Reiley and Pat O?... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question