![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding a columnfrom a specifit line number to a specific line number | Ezy | Shell Programming and Scripting | 2 | 05-12-2008 09:29 AM |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 10:19 AM |
| Number count per number ranges | shirleyeow | Shell Programming and Scripting | 5 | 12-19-2007 04:06 AM |
| to print number one less than actual number | cdfd123 | Shell Programming and Scripting | 4 | 09-06-2007 07:56 AM |
| number pad in vi | c19h28O2 | SUN Solaris | 5 | 09-21-2006 03:41 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
basically helpme.txt has three columns - the first two are decimals and the third is something like 45.5%...
sed is used to discard the % sign as was suggested here earlier... here is the line of code I'm interested in... cat helpme.txt | awk '{$1 $2 $3}NR<5{printf("%-20d %-20d %-20.1f\n",$1,$2,$3)}' | sed 's/%//' | sort $3 the output is correct except for the third column - it disappears to 0 values, or rather 0.0 so i am confused. Are there other options I have which don't lose this value? I expected to see 45.5 in the third column of the output. If anyone can give me another hint I would greatly appreciate it as I can't find other alternatives at this point. -- or is there a way of formatting this output into fixed width columns without it all being the same, ie some fields text and others decimal in the same column? |
|
||||
|
The input would be something like Code:
435 1345 45.5% 12345 345676 29% The output is now Code:
435 1345 0.0 12345 345675 0.0 The third column somehow loses its value when I use the printf formatting to widen the columns... declaring the third column floating point. thanks |
|
||||
|
it works
Your command works fine for me. I feel the sed isn't necessary and the sort should be based on key - syntax is Code:
sort -k3 Code:
$>echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20.1f \n " ,$1,$2,$3)}'|sed 's/%//'
12 13 45.5
Code:
$>echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20.1f\n",$1,$2,$3)}'
12 13 45.5
|
|
||||
|
Also, when I add a fourth field why does the output double space the lines? Code:
echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20d %-20.1f\n",$1,$1,$2,$3)}'
i'm only new at UNIX and it seems there are no end of little traps and caveats which i don't understand |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|