LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Data manipulation (https://www.linuxquestions.org/questions/linux-newbie-8/data-manipulation-606149/)

Yogiz 12-11-2007 06:21 PM

Data manipulation
 
Hi there,

I have a bit of a problem with data manipulation below is the output, would it be possible to use a joint command or anything else to produce output file where the numbers in the middle columns mach each other like the first record in the input file.

Code:

Input
=============================
0.918        100        100        1.32
0.918        101        102        1.328
0.926        102        104        1.336
0.926        103        106        1.344
0.934        104        108        1.352
0.934        105        110        1.36
0.942        106        112        1.368
0.942        107        114        1.376
0.95        108        116        1.384
0.95        109        118        1.392
0.958        110        120        1.4
0.958        111        122        1.408
0.966        112        124        1.416
0.966        113        126        1.424
0.974        114        128        1.432
0.974        115        130        1.44
0.982        116        132        1.448
0.982        117        134        1.456
0.99        118        136        1.464
0.99        119        138        1.472
0.998        120        140        1.48

Output
==============================
0.918        100        100        1.32
0.918        101
0.926        102    102        1.328
0.926        103
0.934        104
0.934        105
0.942        106    106        1.344

Thanks in advance.

pixellany 12-11-2007 07:41 PM

I can't see the logic based on what you have shown. At first I thought you meant "write the line to output if cols 2 and 3 are the same".

You will need to describe the logic (algorithm) in more detail.

sundialsvcs 12-11-2007 08:00 PM

There's more than one way to do it, obviously. (Hope I don't sound too much like a Perl-conversant programmer when I say that.) And there are several very powerful tools you can consider.

For example, in any Unix/Linux environment you can use the notion of "piping the output of one program into another" to do things like sorting your input and then processing it. Lots of programs know how to "accept input from STDIN and send it to STDOUT."

One very powerful tool is awk (see: man tt) which is specifically designed for dealing with text files. It is based on a disarmingly-simple premise that is astonishingly useful and powerful.

A step up from that is Perl, a genuine programming-language that is somewhat of "awk on super-steroids."

Start by considering your problem: describe it in terms of an algorithm that can be applied in order to solve it. In Linux/Unix, it is not a question of lacking for the tools to get the job done! The question is merely, how you wish to go about doing it.


All times are GMT -5. The time now is 04:57 AM.