Author Topic: Equivalent of linux 'tr' command  (Read 6348 times)

Robertre

  • New Community Member
  • Posts: 1
  • Hero Points: 0
Equivalent of linux 'tr' command
« on: July 10, 2018, 03:28:57 PM »
Is there a function already built into VS that will effectively do for me what the Linux 'tr' command does? Basically, I have a file with a lot of character sequences (such as '%20') that I'd like to translate directly to other characters (such as ' ' in the case of '%20'). Ideally I'd like to pass two same sized arrays and say have at it. My current approach is to just keep going back to the top of the file or selection and do search and replace over and over again.
I know I could write this pretty easily, but if it's already there, I'd rather use it.
Thanks,
-Rob

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: Equivalent of linux 'tr' command
« Reply #1 on: July 10, 2018, 11:42:15 PM »
Slick regular expressions can do this, but it is tricky to type in the expressions manually.
I have a macro that given a translation table, it constructs the regex for you.
First, create a block of text like this:
 
    abc==>def
    123==>576
 
Select those lines of text and call translateTerms.
This will populate the find-replace dialog with a Perl RE to replace all those terms on the left with those on the right.
The find&replace dialog is populated with:
    Find: "(abc)|(123)"
    Replace: "$(<1>def|<2>576)"

https://community.slickedit.com/index.php/topic,15187.msg57663.html#msg57663

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Equivalent of linux 'tr' command
« Reply #2 on: July 11, 2018, 01:51:23 PM »
In addition if you're running SlickEdit on linux, you can use filter-command to filter a selection through an external command.  So you could use tr directly as well.