TSE: Linux: How to convert TSE for Microsoft Windows grep.s to run on Linux?
Hello,
a. Maybe Semware could consider adding this grep.s to one of the next TSE for Microsoft Windows and TSE for Linux distributions.
b. See the attached grep.s (which should work on both Microsoft Windows and Linux (WSL) (Ubuntu)).
c. Tested successfully with:
TSE for Linux version 4.50.8
grep for Linux version 211
Linux WSL (Ubuntu) 2.0
d. to run it
1. You will have to inform once where your grep version 211 or higher is located on your disk.
Do this once in the top of the program, save and recompile
(Note: I changed also before all this the Linux filename 'grep' to 'greplinux' to distinguish the grep versions between the
one for Microsoft Windows and the one for Linux)
---
#IFDEF LINUX
string grepLinuxPathS[255] = "/mnt/c/temp/tse_linux/greplinux" // change this to the location of greplinux on your disk
#ENDIF
---
2. I changed the following:
In the original grep.s there was this line for Microsoft Windows only:
ok = lDOS(tee32, format(grep;options;"-n";QuotePath(search);files;">";grep_fn),_DONT_PROMPT_|_TEE_OUTPUT_)
So I changed to (all 1 liners) to include also Linux:
#IFDEF WIN32
ok = lDOS(tee32, format(grep;options;"-n";QuotePath(search);files;">";grep_fn),_DONT_PROMPT_|_TEE_OUTPUT_)
#ELSE
#IFDEF LINUX
ok = DOS(format( "/mnt/c/temp/tse_linux/greplinux", " ", options, " ", "-n" , " ", QuotePath(search), " ", files, " ", "|", " ", 'sed -r "s/\x1B\[[0-9;]*[A-Za-z]//g"', " ", ">", " ", grep_fn, " ", "&" ), DOS_SYNC_CALL_FLAGS )
Warn( "<Press any key>" )
#ENDIF
#ENDIF
3. The output of greplinux and redirecting it '>' into a file was originally full of XTerminal escape codes.
4. So I had to convert this. The easiest was with some out of the box command present on (all) Linux distributions.
5. I tried it with 'sed'.
6. That worked OK.
7. I had to add a 'Press any key' Warn() box, without it one did not get a result. Not sure why, but OK it works.
8. So as the output file (=grep_fn) now was then in about plain ASCII so everything started to work as expected (it looks at this moment)
and it behaved like TSE grep for Microsoft Windows.
1. Run the grep.s program (after changing the path to your TSE for Linux 'grep' file once and recompiling
and input your search string, the files in which to search (use the /mnt/c/ ... notation)
and the search options (e.g. -i = ignore case, -o shows only the filename, -s searches subdirectories,
-x searches with regular expressions, ...)
Then press <Enter>
2. I had to add a Warn() box to interrupt otherwise nothing found.
3. Before the output text that grep found and redirected using '>' into a file
was full of XTerminal escape codes.
4. But after filtering out these escape codes (e.g. using 'sed'), and only after that
redirecting it to a file, you got about
plain ASCII text, which TSE could handle as usual.
5. As usual you can open each of the found files by clicking on it
and inspecting it individually.

6. For comparison purposes, if you run the same grep search on TSE for Microsoft
Windows, then this is the result:

with friendly greetings
Knud van Eeden