Korn-shell coding help needed immediately!

Korn-shell coding help needed immediately!

Post by jovi » Sat, 31 Oct 1998 04:00:00



I got an input flat file like this:

*  C141LX--5--P1                -1      X       2.5000E+01
*  C141LX--5--P1                -1      y       2.5000E+01
*  C141LX--5--P1                -1      P       2.5000E+01

my output requirement is:

C141LX--5--P1                   -1      2.5000E+01 2.5000E+01 2.5000E+01

please let me know if anyone can assist me with K-shell codidng. Thanks

 
 
 

Korn-shell coding help needed immediately!

Post by Icarus Spar » Sun, 01 Nov 1998 04:00:00



Quote:>I got an input flat file like this:

>*  C141LX--5--P1            -1      X       2.5000E+01
>*  C141LX--5--P1            -1      y       2.5000E+01
>*  C141LX--5--P1            -1      P       2.5000E+01

>my output requirement is:

>C141LX--5--P1                       -1      2.5000E+01 2.5000E+01 2.5000E+01

>please let me know if anyone can assist me with K-shell codidng. Thanks

awk '
$2 == saved { printf(" %s",$5) ; }
$2 != saved { if (NR>1) print
                printf("%-32s%-8s%s",$2,$3,$4)
                saved=$2
        } '

assuming that I understand your question

 
 
 

Korn-shell coding help needed immediately!

Post by Randalf J. Mc Murp » Sun, 01 Nov 1998 04:00:00



>I got an input flat file like this:

>*  C141LX--5--P1               -1      X       2.5000E+01
>*  C141LX--5--P1               -1      y       2.5000E+01
>*  C141LX--5--P1               -1      P       2.5000E+01

>my output requirement is:

>C141LX--5--P1                  -1      2.5000E+01 2.5000E+01 2.5000E+01

The script below will take input data like

C141LX--5--P1               -1      X       1.5000E+01
C141LX--5--P1               -1      y       2.5000E+01
C141LX--5--P1               -1      P       3.5000E+01
D141LX--5--P1               -1      X       10.5000E+01
D141LX--5--P1               -1      y       20.5000E+01
D141LX--5--P1               -1      P       30.5000E+01

and spit it out like

C141LX--5--P1 -1 1.5000E+01 2.5000E+01 3.5000E+01
D141LX--5--P1 -1 10.5000E+01 20.5000E+01 30.5000E+01

You'll have to fix up the %s widths, but no big deal.

#!/usr/bin/perl

$record = 1;

while(<>)
{
   chop;
   split;

   if ($record == 1)
   {
      $field_0 = $_[0];
      $field_1 = $_[1];
      $field_2 = $_[3];
      $record++;
      next;
   }

   if ($record == 2)
   {
      $field_3 = $_[3];
      $record++;
      next;
   }

   if ($record == 3)
   {
      $field_4 = $_[3];
      $record = 1;
   }

   printf (STDOUT "%s %s %s %s %s\n",$field_0,  # Modify the %s widths to suit
                                     $field_1,
                                     $field_2,
                                     $field_3,
                                     $field_4);

Quote:}

# End

--
Randalf J. Mc Murphy

 
 
 

1. Korn shell help with remote shell needed!

I wrote this Korn shell script and it works great.  I make 2 calls to rsh
in my script and when it encounters a machine it doesn't 'trust', I get
Permission denied. errors.  Now I know why I'm getting the errors but how do
you stop this message from being displayed to stdout (or stderr).  I tried

Any assistance would be greatly appreciated!

--
John M. Kimball         Xyvision Inc.
(617) 245-4100 x. 5462  101 Edgewater Drive  

Well if I seem a little strange, Well that's because I am!

2. Freebsd newbie

3. c-shell script won't run from korn-shell / SETUID

4. new issue after installing mozilla-1.2.1.0_rh8_xft.i386.rpm

5. best korn shell resources and is there a korn shell faq

6. 2.5.1 problem with TRI/P Token Ring

7. I need help in Korn Shell

8. How to know if a web page/file is downloaded completely

9. SYSOUT & ERROR Logging in Korn Shell - Help Needed!

10. need help with a chmod script in korn shell

11. Need help wit korn shell syntax

12. Need help automated login via korn shell

13. howto add korn shell help needed