Problem with type-casting in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with type-casting in awk
# 15  
Old 01-30-2009
awk

du -ah | awk '$1 > s' s="$filesize" is not working properly. Its only comparing the first digit of the size.
# 16  
Old 01-30-2009
To be honest, I don't know what you are doing wrong. Since I already showed my code is working, here a simple example that Franklin52's code is working too. Instead on depending on du's switches, I used the posted output in an input file:

Code:
root@isau02:/data/transfer> cat infile
28270   .
28170   ./OMautomation
27926   ./OMautomation/pqms
26096   ./OMautomation/pqms/EDM_Batch20080907.log
1744    ./OMautomation/pqms/REDX20080907.log
242     ./OMautomation/pvd
52      ./core
42      ./OMautomation/pqms/MOR_Batch20080907.log
22      ./OMautomation/pvd/062608_040000_wrapper_2.log
22      ./OMautomation/pvd/062508_040000_wrapper_2.log
18      ./OMautomation/pvd/062708_040000_wrapper_2.log
8       ./OMautomation/pvd/080708_183000_wrapper_1.log
8       ./OMautomation/pvd/071408_183000_wrapper_1.log
8       ./OMautomation/pvd/071108_183000_wrapper_1.log
8       ./OMautomation/pvd/071008_183000_wrapper_1.log
8       ./OMautomation/pvd/070908_183000_wrapper_1.log
8       ./OMautomation/pvd/070808_183001_wrapper_1.log
8       ./OMautomation/pvd/070708_183000_wrapper_1.log
8       ./OMautomation/pvd/070408_183000_wrapper_1.log
8       ./OMautomation/pvd/070308_183000_wrapper_1.log
8       ./OMautomation/pvd/070208_183000_wrapper_1.log
8       ./OMautomation/pvd/070108_183000_wrapper_1.log
8       ./OMautomation/pvd/063008_183000_wrapper_1.log
8       ./OMautomation/pvd/062708_183000_wrapper_1.log
root@isau02:/data/transfer> read fs; awk '$1 > fs {print $0}' fs=$fs infile
1000
28270   .
28170   ./OMautomation
27926   ./OMautomation/pqms
26096   ./OMautomation/pqms/EDM_Batch20080907.log
1744    ./OMautomation/pqms/REDX20080907.log


$1 is working the 1st field, not the first digit. awk is like that.
# 17  
Old 01-30-2009
Sadly it isnt working even now....and one thing is for sure, it has got nothing to do with du. Because the output i posted was a sample one, not the complete form of du and still the code you gave wasnt working. It's very frustrating Smilie. Have been working on this for more than a day.
# 18  
Old 01-30-2009
Ok, I have a suggestion. Just do that du you are using and post the original output of here piped in a head -20.
# 19  
Old 01-30-2009
Code:
du -a . | head -20 

output : 

2       ./.profile
2       ./local.cshrc
2       ./local.login
2       ./local.profile
2       ./abat.ksh
22      ./OMautomation/pvd/062508_040000_wrapper_2.log
4       ./OMautomation/pvd/062508_161049_wrapper_2.log
8       ./OMautomation/pvd/062508_183000_wrapper_1.log
22      ./OMautomation/pvd/062608_040000_wrapper_2.log
8       ./OMautomation/pvd/062608_183000_wrapper_1.log
18      ./OMautomation/pvd/062708_040000_wrapper_2.log
8       ./OMautomation/pvd/062708_183000_wrapper_1.log
4       ./OMautomation/pvd/063008_040000_wrapper_2.log
8       ./OMautomation/pvd/063008_183000_wrapper_1.log
4       ./OMautomation/pvd/070108_040000_wrapper_2.log
8       ./OMautomation/pvd/070108_183000_wrapper_1.log
4       ./OMautomation/pvd/070208_040000_wrapper_2.log
8       ./OMautomation/pvd/070208_183000_wrapper_1.log
4       ./OMautomation/pvd/070308_040000_wrapper_2.log
8       ./OMautomation/pvd/070308_183000_wrapper_1.log

# 20  
Old 01-30-2009
Solaris has several flavors of awk. Which version of awk are you using - awk, oawk or nawk? Try using /usr/xpg4/bin/nawk.
# 21  
Old 01-30-2009
Ok, now do this:

Code:
du -a . | head -20 | awk '$1 > 20 {print $1}'

You should get:

Code:
22      ./OMautomation/pvd/062508_040000_wrapper_2.log
22      ./OMautomation/pvd/062608_040000_wrapper_2.log

If not, then I have no clue anymore.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Very strange output with casting

Hi All, I am having a strange issue. Below is the code snippet. If I print fraction * (double)::pow((double)10,scalingFactor) which is a double I am getting 154 when I type cast that to int as (int)( ((fraction) * ((double)::pow((double)10,scalingFactor)))) it is becoming 153. Not sure why... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

2. Shell Programming and Scripting

Casting the data command !

Hey guys. 1st problem: I have to create a script for every hour run a script against a DB and then produce results to log file and eventually email. I have to manipulate the date command from something like this date '+%F %H:%M.%s' which produces the below the below result 2014-08-01... (2 Replies)
Discussion started by: mo_VERTICASQL
2 Replies

3. Shell Programming and Scripting

Type casting problem

hi guys, i m new to shell script.. i dont know how to type cast string into integers and i mention my problem below.. date="21091988" month=$((${date:2:2})) # extract the month from previous date variable temp=$(($month*23)) when i am trying to calculate the temp value i got the... (5 Replies)
Discussion started by: raadhaakrishnan
5 Replies

4. Programming

C++ type-casting a member variable in const methods

Is it permitted to type-cast a member variable passed in as a parameter in a member const method .. I am doing something like : in a return-type method () const { variable other = long(member variable) } this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies

5. UNIX for Advanced & Expert Users

How type casting works ?

I am having a doubt with type casting in C. Very often in network programming, we have something like this: char *data = ...; struct iphdr *ip = (struct iphdr *) data; where iphdr is define in netinet/ip.h. Let us say that the size of the content of held by 'data' is much more than... (1 Reply)
Discussion started by: radiatejava
1 Replies

6. Shell Programming and Scripting

Find problem listing directories even -type f

Hi All, #!/bin/ksh find /home/other -ls -type f -xdev | sort -nrk7 | head -2 >bigfile.txt The above is my script, which writes the large file into a file called bigfile.txt. My script contains only the above two lines. after execution i am getting the output like find: cannot chdir to... (1 Reply)
Discussion started by: Arunprasad
1 Replies

7. Shell Programming and Scripting

casting

Hi everyone, I was wondering how i could cast a floating value to an integer in csh Thanks (0 Replies)
Discussion started by: ROOZ
0 Replies

8. Shell Programming and Scripting

Stuck on a matching, copying type problem

Hi all, I am new to these forum and to scripting in general for that matter. i have been looking through the forums for something that could explain my problem. I have be come pretty familiar with sed and awk but I can not seem to figure this out... I am trying to match data from 3 files but every... (4 Replies)
Discussion started by: derek3131
4 Replies

9. UNIX for Advanced & Expert Users

terminal type problem with cygwin on aix

hey, I use cygwin to connect to AIX 5.2 but when I open vi I get an error saying: ex: 0602-108 cygwin is not a recognized terminal type how can I fix that? I thought cygwin was tty vt100? (1 Reply)
Discussion started by: rein
1 Replies

10. Shell Programming and Scripting

Problem with variable type

Dear All, I am trying to write an script to calculate geometric centre of selected residues of a protein structure. Say I have a PDB file (a text containing the x, y, and z coordinates of atoms of a protein). I want to extract the X coordinates of the atoms belonging to the interested residues... (2 Replies)
Discussion started by: siavoush
2 Replies
Login or Register to Ask a Question