Link to home
Start Free TrialLog in
Avatar of sigma
sigma

asked on

Changing a Logfile

I like to change a file like here below
--------------------------------------------------------------
NET NAAM: 'FSW6';
              NODE(S): X1A.B12  S6.3 ;
 
NET NAAM: 'GND';
              NODE(S): G1.7  D5.7  D4.7  D3.7  D2.8  D1.8
                       V3.2  C3.2  R25.1  R20.1  R13.2  R18.2
                       R27.1  C10.2  C9.2  C8.2  C7.2  C6.2
                       C5.2  C4.2  C1.2  C2.2  X1A.B10  X1A.B6
                       X2A.B16  X2A.A20  X2A.A13  S16.B12
                       S16.B1 ;
--------------------------------------------------------------
I 've need a script sothat the file will be like here below
--------------------------------------------------------------
FSW6                   X1A.B12  S6.3
GND                    G1.7  D5.7  D4.7  D3.7  D2.8  D1.8
                       V3.2  C3.2  R25.1  R20.1  R13.2  R18.2
                       R27.1  C10.2  C9.2  C8.2  C7.2  C6.2
                       C5.2  C4.2  C1.2  C2.2  X1A.B10  X1A.B6
                       X2A.B16  X2A.A20  X2A.A13  S16.B12
                       S16.B1
--------------------------------------------------------------
I'm working on a SUNos system with a Csh shell scripts for
doing this only the problem is :
How can I get the line with NODE(S) on the back from the
line NET NAAM? Can I use sed for removing strings in more
then one line?
When somebody knows a solution for this give me
suggestions please. Thanks a lot for helping.

                Sigma
Avatar of leendert
leendert

Hi there,

here is a simple sed that will help you out :
Bare in mind that this small window does wrapping. The following
line is a one liner...

sed "s/NET NAAM: '//g;s/';//g;s/NODE(S): //g;s/;//g;/^$/d"

You will have to cat your logfile through this line of script.

Eg :
cat logfile | sed "s/NET NAAM: '//g;s/';//g;s/NODE(S): //g;s/;//g;/^$/d"



Output generated :
------------------

FSW6
  X1A.B12 S6.3  
GND
  G1.7 D5.7 D4.7 D3.7 D2.8 D1.8
  V3.2 C3.2 R25.1 R20.1 R13.2 R18.2
  R27.1 C10.2 C9.2 C8.2 C7.2 C6.2
  C5.2 C4.2 C1.2 C2.2 X1A.B10 X1A.B6
  X2A.B16 X2A.A20 X2A.A13 S16.B12
  S16.B1

If there is still a bit of tweeking needed please let me know.

Hope this will help you ...
Leendert.
Hi again,

After you applied the sed script I mentioned above,
you can also do the following script. If the names of the
node is always smaller than 6 characters this script will
change the format of the output file exactly as you wanted.

Here is the script :
cat logfile | while read A;
do
    Len=`echo $A | wc -c`
    if [ "$Len" -lt 6 ]
    then
        echo $A | tr -d '\n'
    else
        echo "  $A"
    fi;
done


Output generated :
FSW6  X1A.B12 S6.3
GND  G1.7 D5.7 D4.7 D3.7 D2.8 D1.8
  V3.2 C3.2 R25.1 R20.1 R13.2 R18.2
  R27.1 C10.2 C9.2 C8.2 C7.2 C6.2
  C5.2 C4.2 C1.2 C2.2 X1A.B10 X1A.B6
  X2A.B16 X2A.A20 X2A.A13 S16.B12
  S16.B1

Hope this solved your problem.

Leendert.
this also is one linle in your shell:

cat file | sed -e '/^[@]*$/d;s/;//g' -n -e "/NET NAAM:/{;s/NET NAAM:'\(.*\)'/\1/;N;s/;//g;s/\n[@]*NODE(S)://p;n;};p"


``@''  above must be replaced by a blank followed by a tab.

But I would recommend to use (g)awk, because it will be much
faster (on Suns Solaris) than sed (I think you have huge
netlist files:-).

Ciao
Achim

Achim


Avatar of sigma

ASKER

Hi Leendert

First script is not working     >> Illegal variable name.
Second is also not working      >> while: Expression Syntax.

This is with shell command as in a script !!

  Sigma
Sigma,

leendert's examples must be used in (k)sh.

> First script is not working >> Illegal variable name.
problem is the  ``$''  in the sed's subdtitute command. Replace
it by   ``$d''  and set a local csh-variable:

      set d = '$'

before evaluating the sed command.

> Second is also not working >> while: Expression Syntax.
This is sh syntax. Put it in a file and make it executable,
or rewrite with csh syntax, or simly start a sh and then execute.

Ciao
Achim
Thanks Achim for the above comments,

You're answer is better than mine in this case (csh compatible) :^). I missed that in the question. Better read the thing
more carefully next time ...

Leendert.
Avatar of sigma

ASKER

Hi

It's working fine but I lose the lines without
NODE(S) and NET NAAM
I 'll find a solution for that.
Thanks a lot both of you Leendert & Achim

  Sigma
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you loose the non-matching lines, you may have lost one of
the sed's  ``p''  commands (the last one), check it.
You can try omitting the  -n  option to the sed, you then should
get the  NET NAAM  lines twice.
Also note that bash doesn't allow typing a tab on the command
line (i.g. its used for file completion), just omit it if there
are no tabs in your file.

Achim