• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. grep doesn't work from system(), but does from terminal...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 2082
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

grep doesn't work from system(), but does from terminal, how to fix?

Sheppie
Sheppie over 4 years ago

Hello,

As part of a script to fix port-orders (yes, I know, we could have a whole debate about port-order or terminal order, but let's park that for now...) I want to automatically process a CDL netlist file using a combination of grep and sed, in order to create a new file which will be used by the SKILL script. This is the tried and tested command which does exactly what I want, and it runs perfectly from a terminal:

grep -Pzo '.SUBCKT P.+\n.*' ./scripts/io_gppr_cln22ul_t25_mv09_mv33_fs33_svt_dr.cdl | grep -v '^*' | sed 's#.SUBCKT ##' | sed -z 's#\n+##g' | sed 's#  # #g' | sed 's# #,#g' > termOrder.input

It reads a CDL netlist file, looks for all lines that start with ".SUBCKT P", selects this whole line AND the next line. The second grep removes all lines which start with a "*". Multiple sed commands are used to remove the ".SUBCKT P" part, replace a new-line and + with nothing, replacing double spaces with single spaces and finally it replaces all (now single) spaces by a ",". This all is stored in the file termOrder.input.

This all works from the same terminal from which I launch Virtuoso.

Since I want to automate this into the script, I tried the following in the CIW:

sourceNetlist = "/users/sh033860/workarea/xp4000/scripts/io_gppr_cln22ul_t25_mv09_mv33_fs33_svt_dr.cdl"
command = strcat("grep -Pzo '.SUBCKT P.+\n.*' " sourceNetlist " | grep -v '^*' | sed 's#.SUBCKT ##' | sed -z 's#\n+##g' | sed 's#  # #g' | sed 's# #,#g' > termOrder.input" )
system( command )

And this fails... The output in the terminal is:

[tsmcN22@utc0vnc002 cds]$ grep: the -P option only supports a single pattern
sed: -e expression #1, char 2: unterminated `s' command

However, when I first open a terminal from the CIW by doing this:

system( "xterm" )

And then, in this new terminal past the same line as constructed by command = ....., it works.

I truly hope someone can explain to my why it doesn't work from using system( command ), but it works manually. It would be very handy to be able to automate this step (and I will use this more often in the future).

Having said that, if something like this can be done fairly easily using SKILL (reading a CDL file and processing it on the fly), I'm more than happy to do it like that.

Many thanks in advance.

With kind regards,

Sjoerd

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 4 years ago

    Hi Sjoerd,

    The issue is with the \n in your command (both of them). You need these to be passed to the command, but the problem is that they are being interpreted by SKILL (and so converted at that point to be a newline). If you change the command to:

    command = strcat("grep -Pzo '.SUBCKT P.+\\n.*' " sourceNetlist " | grep -v '^*' | sed 's#.SUBCKT ##' | sed -z 's#\\n+##g' | sed 's#  # #g' | sed 's# #,#g' > termOrder.input" )

    then it should work (it did for me - although on my RHEL6.5 machine sed doesn't support -z, but I removed that for the purposes of experimentation and it worked). In other words, I changed both \n to \\n.

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sheppie
    Sheppie over 4 years ago in reply to Andrew Beckett

    Hi Andrew,

    Not again... I've made this same mistake a few times in the past. Clearly not something that sticks.

    And yes, you're right, that was the problem. Added a few back-slashes and it all works. Thanks for pointing out the obvious to me.

    Kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information