Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing a Logfile

Posted on 1997-06-26
9
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 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