简体   繁体   中英

Reordering the contents of a file using tcl

I'm a newbie to Tcl and code writing in general. I have what seems like a simple coding issue that I have about 10 hrs into that I can't seem to resolve. I have a file that contains a list of nets clk123, n789, clk456, n246…. I need to reorder the list so that the clk* nets appear first when outputted. I can read the files in question and output the contents to the monitor or a file. But, I'm not able to find a way to reorder the list. I've spent so much time researching this that I'm now completely confused. Can someone offer a suggestion?

If there's just clk* and n* nets, a simple sort should be sufficient:

package require fileutil

proc sort data {
    set lines [split $data \n]
    set lines [lsort $lines]
    join $lines \n
}

::fileutil::updateInPlace thefile.txt sort

Documentation: fileutil package, join , lsort , package , proc , set , split

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM