• 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 string pattern from file skill

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 143
  • Views 12554
  • 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 string pattern from file skill

saurabh96
saurabh96 over 4 years ago

Hey,

How to grep a string pattern "Hello run completes" from file.txt and if output founds print "Hello run completes" in virtuoso ciw else print "error run uncompleted" in ciw.

I have tried this way..but its simply putting output without checking:-

sumfile = simplifyFilename("getWorkingDir/file.txt")
if(system(strcat("grep " "'" "Hello run completes" "'" " sumfile>sumfile.out" )) = t then
printf("Hello run completes")
else
printf("error run uncompleted")
)

Any help would be highly appreciated!

Regards,

SRV

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 4 years ago

    There's actually an example of doing this in the "Related Thread" list below this post:  Search for a string pattern inside a file . Your post has changed since you first posted it, as it was originally using pcreCompile (but not calling pcreExecute) .

    Your code now is a bit strange - I assume the sumfile assignment really wouldn't be looking in a directory called "getWorkingDir" but anyway this works:

    sumfile=simplifyFilename("./file.txt")
    if(system(strcat("grep -q '" "Hello run completes" "' " sumfile))==0 then
      printf("Hello run completes\n")
    else
      printf("error run uncompleted\n")
    )

    This uses -q on the grep to silently check, and correctly uses the return status of the command (0 means success) rather than t/nil (the exit status is always going to be "true" so that wouldn't work in your code).

    Andrew

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

    Thanks Andrew..

    Appreciate you guidance!!

    one more query i have...suppose i have run file(abc.sh)  which i run on shell terminal to launch any tool x.

    Now, if i have to ran same file..i.e abc.sh from skill file...

    is it right way to do it?

    sh(./abc.sh)

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

    You'd need to put quotes around the string, of course. You could use:

    sh("./abc.sh")

    or

    system("./abc.sh")

    or 

    ipcBeginProcess("./abc.sh")

    depending on how you want to interact with and get information from the child process. I suggest you read the documentation to determine which makes most sense.

    Andrew

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

    Hey everyone,

    for the above post i have tried to store the output coming and then display through dialog box...but am getting value 0 in final log..how to correct that error?

    sumfile=simplifyFilename("./file.txt")
    final_log = (system(strcat("grep  '" "Hello rule abc completes" "' " sumfile  | head -1)) ;;;;  (head -1  to only store the first string match) 
      hiDisplayAppDBox( ?name 'errorbox2 ?dboxBanner "success" ?dboxText final_log ?buttonLayout 'Close ?buttons 'Cancel)

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

    Please try reading the documentation for system. You'll see that it returns the exit status of the command executed, not the output. You'd need to use ipcBeginProcess if you want to read the output of the command executed.

    So many of your questions could easily be solved if you read the documentation!

    Andrew

    • 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