LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-19-2010, 03:13 PM   #46
ilukacevic
LQ Newbie
 
Registered: Jul 2010
Posts: 22

Original Poster
Rep: Reputation: 0

Quote:
Originally Posted by MTK358 View Post
I don't understand the output format. What exactly is happening and what are those dots doing?
I apologize for not making the output more clear.

I should take column (141 rows) after column (6 of them) from the input file, put the next one under the previous one. That would be the 2nd column of the output. In the 1st column of the output should the line numbers go (141 of them for each column -> 6 times like that => 846 rows in total in the output file and 2 columns).

Dots are data not reprezented in my post...there is a lot of data, so I truncated the input file, without loosing the main features.


thnx for the effort!

Igor
 
Old 07-19-2010, 03:44 PM   #47
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Still quite confused.

Also, do you still want some multiplication to happen?
 
Old 07-19-2010, 03:47 PM   #48
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Ok.. it's clear now. I will suggest my previous awk code (see post #23) with a little modification to specify the format of the numeric results. I'm sure grail and MTK358 will refine their suggestions, as well.
Code:
BEGIN { OFMT = "%.6f"; factor = 219474.6306726 }

{
  gsub(/D/,"E")
  
  for ( i=1; i<=NF; i++ )
     array[++count] = $i
}

END {
  for ( i=1; i<=count/NR; i++ ) {
    for ( j=0; j<NR; j++ ) {
      print j+1, array[i+j*NF] * factor
    }
  }
}
This is independent from the number of rows and columns. The OFMT variable controls the format of the numeric output with the print statement.

Last but not least, two advices for good awk readings:
1. the official GNU awk manual: http://www.gnu.org/software/gawk/manual/
2. the grymoire's awk tutorial: http://www.grymoire.com/Unix/Awk.html
Hope this helps!
 
Old 07-19-2010, 04:01 PM   #49
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Code:
#!/usr/bin/env perl
use warnings;
use strict;

my $filename = $ARGV[0];
open my $file, $filename or die "error: $filename: could not open";

for my $col (0 .. 5) {
    my $linenum = 0;
    seek $file, 0, SEEK_SET;

    while (<$file>) {
        $linenum++;
        my @cols = split;
        print "$linenum" . $cols[$col] * 219474.6306726 . "\n";
    }
}
 
Old 07-19-2010, 07:23 PM   #50
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,431

Rep: Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878Reputation: 1878
Well mine and colucix's are just variations on a theme, but just so you have other stuff to look at
Code:
#!/usr/bin/awk -f

BEGIN { OFMT = "%.6f"; factor = 219474.6306726 }

{
    gsub(/D/,"E")

    for(i=1;i<=NF;i++)
    {
        if(arr[i])
            arr[i]=arr[i]"\n"

        arr[i]=arr[i]NR" " $i * factor
    }
}

END{
    for(x=1;x<=NF;x++)
        print arr[x]
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Column statistic by awk ? cs24 Programming 7 01-15-2010 05:41 AM
Read text file column by column RVF16 Programming 11 05-31-2009 07:16 AM
Change column value with AWK RyudoBlaze Programming 2 04-25-2009 03:05 AM
Concatenate column 1 and column 2 of related lines cgcamal Programming 4 11-20-2008 10:43 AM
awk column printing schneidz Programming 7 09-29-2005 06:14 AM


All times are GMT -5. The time now is 10:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration