Solved

Changing a Logfile

Posted on 1997-06-26
9
233 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:sigma
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:leendert
ID: 1293750
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.
0
 
LVL 1

Expert Comment

by:leendert
ID: 1293751
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1293752
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


0
 

Author Comment

by:sigma
ID: 1293753
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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 1293754
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
0
 
LVL 1

Expert Comment

by:leendert
ID: 1293755
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.
0
 

Author Comment

by:sigma
ID: 1293756
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
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 60 total points
ID: 1293757
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
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1293758
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
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 81
Host to IP 7 73
maxBlock challenge 30 100
Window placement 17 65
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now