Author Topic: How to run external tool to sort lines  (Read 4482 times)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
How to run external tool to sort lines
« on: January 27, 2009, 03:30:06 PM »
How to run external tool to sort lines


See an video on YouTube about this topic ==> http://www.youtube.com/watch?v=eKpu9_0Q7wY



1.) open an file which use your favorite syntax
2.) open "Tools > Manage Tools ( )"
3.) If you want, check "[ ] Show All Syntaxes" to chose an other synatx,
     you may use one of the "default" synatx to use this tool for all syntaxs
4.) once you have chosen your synatx, click on the right side on [Add...]

5.)
Title: chose an nice title your self
Command: sort                        ___this should run sort.exe from your "C:\WINDOWS\system32" dir
Arguments: %FileName%          ___see the arrow on the right?
Save before: Current document ___because the sort.exe use this as input
[X] Capture output                    ___don't modify Output pattern

6.)
[ OK ]
[ OK ]


7.) have an (test ! )-file with some lines
8.) execute your new tool
9.) View > Windows > Output
10) now you can copy this output and overwrite your document
« Last Edit: February 08, 2009, 06:29:40 PM by Stefan »
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
How to run external tool to sort lines containing patterns?
« Reply #1 on: January 27, 2009, 04:40:33 PM »
How to run external tool to export lines containing patterns?

Download SFK
Quote
Swiss File Knife - the open source file tree processor
is a free multi function command line tool that belongs onto every usb stick.
from
Homepage: http://stahlworks.com/dev/index.php?tool=sfk
Download: http://sourceforge.net/project/showfiles.php?group_id=160478&package_id=180544

Copy the sfk.exe in an folder on your system path, f.ex. to C:\Windows


1.) open an file which use your favorite syntax
2.) open "Tools > Manage Tools ( )"
3.) If you want, check "[ ] Show All Syntaxes" to chose an other synatx,
     you may use one of the "default" synatx to use this tool for all syntaxs
4.) once you have chosen your synatx, click on the right side on [Add...]

5.)
Title: chose an nice title your self
Command: sfk                                                               ___this should run sfk.exe from your "C:\WINDOWS\" dir
Arguments: filter %FileName% -+%Variable name%       ___see the arrow on the right?
Save before: Current document                                       ___because the sfk.exe use this as input
[X] Capture output                                                          ___don't modify Output pattern yet

Note: 'filter '  and ' -+ '   are arguments of  sfk.exe,  %FileName%   and %Variable name%     are args from HippoEDIT
Quote
C:\>sfk filter
sfk filter [fileOrDir] -selectoption(s) -processoption(s)
sfk filt -selectoption(s) -processoption(s) -dir mydir -file .ext1 .ext2
sfk filter [-memlimit=n] -write inoutfile -replacepattern(s)

   filter and change text lines, from standard input, or from file(s).
   input lines may have a maximum length of 4000 characters.

   line selection options
      -+pat1 -+pat2 [...]   - include lines containing pat1 OR  pat2
      ++pat1 ++pat2 [...]   - include lines containing pat1 AND pat2
      -ls+pat1              - include lines starting with pat1
      -le+pat1 -le+pat2     - include lines ending   with pat1 OR pat2

      -!pat1 -!pat2         - exclude lines containing pat1 OR  pat2
      -ls!pat1              - exclude lines starting with pat1
      -le!pat1 -le!pat2     - exclude lines ending with pat1 or pat2
      -no-empty-lines       - exclude empty lines
      -no-blank-lines       - exclude lines containing just whitespaces
      -unique [-case]       - if same line occurs twice, keep only first.
                              default is case insensitive text comparison.
      -inc[lude] p1 to p2   - include only lines within blocks surrounded by
                              boundary lines containing patterns p1 or p2
      -inc-      p1 to p2   - same, but exclude boundary lines on output
      -cut[-]    p1 to p2   - remove block of lines from p1 until p2
      -inc[-]    "*" to p1  - include all from text start until marker
      -cut[-]    p1 to "*"  - cut all from marker line until end of text
      -nocheck     - with inc, cut: ignore block endings without a start
      -addmark txt - with inc, cut: insert txt after every processed block


6.)
[ OK ]
[ OK ]


7.) have an (test ! )-file with some lines
like this (shorted) parts from an Total Commander History file:

22.11.06  Release Total Commander 7.0 public beta 2
22.11.06  Fixed: Change Start Menu dialog: Parameters and Start Path fields disabled for internal commands
22.11.06  Added: Lister: Shift+Click to select text from last selection position to current position
22.11.06  Fixed: Alt+Left/Right both scrolled by 30 characters AND copied the marked text to the other panel
22.11.06  Added: For the moment, remove admin shares completely from tree, they just do not work properly.
22.11.06  Added: Show checkmark for command cm_SwitchSeparateTree if one or two trees active
22.11.06  Fixed: Some versions of external LZH unpacker (lha32) seem to ignore target path if it doesn't
22.11.06  Fixed: ZIP to multiple parts: Cancel packing if user clicks cancel in dialog box
22.11.06  Fixed: ZIP to multiple parts: User wasn't asked for part size when no target path was given
22.11.06  Fixed: Logging stopped when log file itself was copied.
21.11.06  Fixed: Icons in "Show" menu lost when changing any of the custom column view options
21.11.06  Fixed: FTP delete directory: Cancel button shown only in half
21.11.06  Fixed: Increased width of listbox with dir tabs by 1 pixel
21.11.06  Fixed: Reduced flickering when adding/removing first tab (Ctrl+T/Ctrl+W)
21.11.06  Added: Add 16 to IconsInMenus value to show selected items in menu as frames with checkmark or icon in it
21.11.06  Fixed: Choose better default color for frames around thumbnails when background color is almost black
21.11.06  Fixed: Compare by content: Save button was active when one of the files was missing




8.) execute your new tool
9.) you will be prompted for an argument (because of %Variable name% part), enter 'Fixed:' here and press ENTER
10) View > Windows > Output (you will see only lines which contain the text 'Fixed:')
11) now you can copy this output and overwrite your document or to create an new doc


Tip: instead of default "%Variable name%" you can use any text inside the two %%, f.ex. "%Enter parameter%"


.

Of course i will suggest this feature as an internal option to filter lines by RegEx phrase :D (like WordStar and PlainEdit have)
« Last Edit: January 27, 2009, 10:30:48 PM by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: How to run external tool to sort lines
« Reply #2 on: January 27, 2009, 08:08:15 PM »
HippoEDIT and SED

Title: chose an nice title your self
Command: sed
Arguments: %Variable name%  %FileName%
Save before: Current document
[X] Capture output 



If you execute this new tool, you will be prompted for an argument.


The syntax of SED is:
C:\>sed
Usage: sed [OPTION]...  [input-file]...

You can google for 'sed one-liners 101' to see what is possible.

Here are some sed one-liners to test:

------------------------------------------------
1.) print every second line only

I have this test text:
1 HippoEDIT is an editor
2 HippoEDIT is portable
3 HippoEDIT use highlighting
4 HippoEDIT supports RegEx
5 HippoEDIT use per syntax settings
6 HippoEDIT have word completion function
7 HippoEDIT provide column editing
8 HippoEDIT edit multi files at once

I execute our new tool and enter:  -n -e "p;n " to get this output:

Command Line:
C:\WINDOWS\system32\sed.exe -n -e "p;n " E:\temp\Untitled2_SED-test.TXT

1 HippoEDIT is an editor
3 HippoEDIT use highlighting
5 HippoEDIT use per syntax settings
7 HippoEDIT provide column editing

-------------------------------------------- Done --------------------------------------------

Execution Time : 00:00:00






------------------------------------------------
2.) print non-commented lines only

I have this test text:
;1 HippoEDIT is an editor
2 HippoEDIT is portable
;3 HippoEDIT use highlighting
4 HippoEDIT supports RegEx
;5 HippoEDIT use per syntax settings
6 HippoEDIT have word completion function
; 7 HippoEDIT provide column editing
8 HippoEDIT edit multi files at once

I execute our new tool and enter:  -n -e "/^[^;].*/p" to get this output:

Command Line:
C:\WINDOWS\system32\sed.exe -n -e "/^[^;].*/p" E:\temp\Untitled2_SED-test.TXT

2 HippoEDIT is portable
4 HippoEDIT supports RegEx
6 HippoEDIT have word completion function
8 HippoEDIT edit multi files at once
-------------------------------------------- Done --------------------------------------------

Execution Time : 00:00:00

Note: wrote your comment symbol at the position shown here as X:  [^X]




------------------------------------------------
3.) print lines only if they contain the word 'Fixed:'

I have this test text:
1 HippoEDIT New:
2 HippoEDIT New:
3 HippoEDIT Fixed:
4 HippoEDIT New:
5 HippoEDIT Fixed:
6 HippoEDIT New:
7 HippoEDIT Fixed:
8 HippoEDIT Fixed:

I execute our new tool and enter:  -n -e "/Fixed:/p" to get this output:

Command Line:
C:\WINDOWS\system32\sed.exe -n -e "/Fixed:/p" E:\temp\Untitled2_SED-test.TXT

3 HippoEDIT Fixed:
5 HippoEDIT Fixed:
7 HippoEDIT Fixed:
8 HippoEDIT Fixed:
-------------------------------------------- Done --------------------------------------------

Execution Time : 00:00:00


Note: instead of 'Fixed:' write your own expression.


---------------------


4.) Change each char in list one
     with the char at the same position in list two:

I have this:
1 HippoEDIT

Command Line:
C:\WINDOWS\system32\sed.exe -e "y/oE/Eo/" E:\temp\Untitled2_SED-test.TXT

I get:
1 HippEoDIT

o is changed to E
E is changed to o

Hint: -e "y/ListOne/ListTwo/"

Here is very simple ROT13:
sed -e 'y/abcdefghijklmnopqrstuvwxyz/nopqrstuvwxyzabcdefghijklm/'

-------------------------------------------- Done --------------------------------------------


-------------------------------------





5.) Search and replace only the n'th occurrence:
     I want to change only the second char 'o' in string to uppercase 'O'

I have this:
HippoEDIT - The Song.mp3
HippoEDIT - I love you.mp3
HippoEDIT - To my aid.mp3

Command Line:
C:\WINDOWS\sed.exe "s/o/O/2" F:\HippoEDIT\Untitled5.TXT

I get:
HippoEDIT - The SOng.mp3
HippoEDIT - I lOve you.mp3
HippoEDIT - TO my aid.mp3


--------

Only in line containing 'love'
Command Line:
C:\WINDOWS\sed.exe "/love/ s/o/O/2" F:\HippoEDIT\Untitled5.TXT

HippoEDIT - The Song.mp3
HippoEDIT - I lOve you.mp3
HippoEDIT - To my aid.mp3

----------

Only in line NOT containing 'love'
Command Line:
C:\WINDOWS\sed.exe "/love/ !s/o/O/2" F:\HippoEDIT\Untitled5.TXT

HippoEDIT - The SOng.mp3
HippoEDIT - I love you.mp3
HippoEDIT - TO my aid.mp3

----------

Change all lower case o's to upper case O's:
Command Line:
C:\WINDOWS\sed.exe "s/o/O/g" F:\HippoEDIT\Untitled5.TXT

HippOEDIT - The SOng.mp3
HippOEDIT - I lOve yOu.mp3
HippOEDIT - TO my aid.mp3
-------------------------------------



6.)

put an new line after every line: "G" (Hint: count 'one line', ' then G=new line)
put an new line after every second line: "n;G" (Hint: count 'one line', 'n ext line' ; 'then G=new line)
put an new line after every third line: "n;n;G" (Hint: count 'one line', 'n ext line' ; 'n ext line' , 'then G=new line)



-----------------


7.)

Revers chars in line

Command Line:
C:\WINDOWS\sed.exe "/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//" F:\HippoEDIT\Untitled5.TXT

3pm.gnoS ehT - TIDEoppiH
3pm.uoy evol I - TIDEoppiH
3pm.dia ym oT - TIDEoppiH


-------

Revers lines

Command Line:
C:\WINDOWS\sed.exe -n "1!G;h;$p" F:\HippoEDIT\Untitled4.TXT

8 HippoEDIT edit multi files at once
7 HippoEDIT provide column editing
6 HippoEDIT have word completion function



--------------------------


8.)


Output lines only not containig pattern '2' (because this lines are 'd'eleted)

Command Line:
C:\WINDOWS\sed.exe "/2/d" F:\HippoEDIT\Untitled4.TXT

1 HippoEDIT is an editor
3 HippoEDIT use highlighting
4 HippoEDIT supports RegEx


---

Output lines only if they contain pattern '2' or '7'

Command Line:
C:\WINDOWS\sed.exe -n "/2\|7/p" F:\HippoEDIT\Untitled4.TXT

2 HippoEDIT is portable
7 HippoEDIT provide column editing



-------------------------


9.)
« Last Edit: January 28, 2009, 02:56:10 PM by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: How to run external tool to sort lines
« Reply #3 on: January 28, 2009, 08:57:43 AM »
HippoEDIT and AWK


C:\>awk
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...

Note: take care of the quotes, UNIX style use ' and '  , Windows use " and "



Command: awk
Arguments: %Variable name%  %FileName%
Save before: Current document
[X] Capture output 





i have this text:

1 HippoEDIT is an editor
2 HippoEDIT is portable
3 HippoEDIT use highlighting
4 HippoEDIT supports RegEx
5 HippoEDIT use per syntax settings
6 HippoEDIT have word completion function
7 HippoEDIT provide column editing
8 HippoEDIT edit multi files at once

i use command "{print "$3,$4,$5,$6,$7,$8"}" to get all columns after column 2

Command Line:
C:\WINDOWS\awk.exe "{print "$3,$4,$5,$6"}" F:\HippoEDIT\Untitled4.TXT

is an editor   
is portable   
use highlighting   
supports RegEx   
use per syntax settings 
have word completion function 
provide column editing   
edit multi files at once

-------------------------------------------- Done --------------------------------------------

Execution Time : 00:00:00




--------------




# Print first two fields in opposite order:
  awk '{ print $2, $1 }' file

I have this text:
One Two Three Four
oNe tWo tHree fOur
one two three four

i use command "{print "$2,$1,$3,$4"}" to reverse the order of the first two columns


Command Line:
C:\WINDOWS\awk.exe "{print "$2,$1,$3,$4"}" F:\HippoEDIT\Untitled6.TXT
   
Two One Three Four
tWo oNe tHree fOur
two one three four

-------------------------------------------- Done --------------------------------------------

Execution Time : 00:00:00




---------------