• 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. Sort file-data

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 8267
  • 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

Sort file-data

Mabr86
Mabr86 over 2 years ago

Hello,

i have a file with the following content:

7.5 (66.3 13.9)
2.2 (69.75 19.75)
36 (65.45 21.25)
3.3 (65.35 19.9)
7.5 (56.15 25.3)

I want to sort the data based on the number in front. The result should be:

2.2 (69.75 19.75)
3.3 (65.35 19.9)
7.5 (66.3 13.9)
7.5 (56.15 25.3)
36 (65.45 21.25)

Can anyone help me with the code? I tried it with "while(gets(...)" and sortcar, but it doesn´t work because i can´t convert the individual lines into lists. 

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    fp=infile("file.txt")
    data=nil
    while(line=lineread(fp)
      data=cons(line data)
    )
    close(fp)
    data=sortcar(data 'lessp)

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Mabr86
    Mabr86 over 2 years ago in reply to Andrew Beckett

    Thank you! Now the whole list is in one line. Can the list be formatted so that the results are one below the other?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to Mabr86

    foreach(line data printf("%L\n" line)) t

    It all depends on what you're planning to do with the results - a list is a list - it's up to you how you display it.

    Andrew 

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to Mabr86

    foreach(line data printf("%L\n" line)) t

    It all depends on what you're planning to do with the results - a list is a list - it's up to you how you display it.

    Andrew 

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
No Data

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