(view source code of cut.cmd as plain text)
/* * * * * * * * * * * * * * * * * * * * * * * * * *//* Attempt to "port" the Unix CUT command to Rexx *//* Rob van der Woude, May 16 1998 - June 4 2000 *//* Usage: any_command | CUT { -C:n | -F:n *//* [ -D:"any_string" [ -I ] ] } [ -L:n ] *//* [ -S ] [ -V:varname ] [ -X:command ] *//* * * * * * * * * * * * * * * * * * * * * * * * * *//* Load RexxUtil */if RxFuncQuery( "SysLoadFuncs" ) <> 0 then do
call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
call SysLoadFuncsend/* Parse and check command line */parse arg cmdline
cmdline = translate( cmdline, '-', '/' )
parse value cmdline with cmdline'-x:'xcommand
if xcommand = "" then parse value cmdline with cmdline'-X:'xcommand
cmdline = strip( cmdline )
parse upper value cmdline with .'-C:'column .
parse value cmdline with .'-d:"'delimiter'"'.
if delimiter = '' then parse value cmdline with .'-D:"'delimiter'"'.
parse upper value cmdline with .'-F:'field .
parse upper value cmdline with .'-L:'length .
parse upper value cmdline with .'-V:'variable .
ipos = pos( ' -I', translate( cmdline ) )
if ipos = 0 then do
case = ''
endelse do
if ipos > lastpos( '"', cmdline ) | ipos < pos( '"', cmdline ) then do
case = 'upper'
delimiter = translate( delimiter )
endelse do
case = ''
endendspos = pos( ' -S', translate( cmdline ) )
if spos = 0 then do
skip = 0
endelse do
if spos > lastpos( '"', cmdline ) | spos < pos( '"', cmdline ) then do
skip = 1
endelse do
skip = 0
endendselectwhen column <> '' & field <> '' then call Syntax
when length <> '' & datatype( length, 'W' ) <> 1 then call Syntax
when field <> '' then do
if datatype( field, 'W' ) <> 1 then call Syntax
cuttype = 'WORD'
cutpos = field endwhen column <> '' then do
if delimiter <> '' then call Syntax
if datatype( column, 'W' ) <> 1 then call Syntax
cuttype = 'CHAR'
cutpos = column endotherwise call Syntax
endcutlen = 0
if length <> '' then cutlen = length
if delimiter = '' then delimiter = ' '
if variable = '' then variable = 'CUT'
/* Purge variable */call value variable, "", "OS2ENVIRONMENT"
/* Read Standard Input */empty = 0
do i = 1 by 1 while lines( ) > 0
parse pull line.i
if line.i = "00"X then leave
if line.i = "1A"X then leave
if line.i <> "" then empty = 0
if line.i = "" then empty = empty + 1
/* Stop after 100 empty lines */if empty > 100 then leave
end/* Ignore those 100 empty lines */line.0 = i - 100
/* Cut lines as specified on command line */cuttot = cutpos + cutlen
do i = 1 to line.0
if line.i = "" then do
msg = ""
call Output iterate endif cuttype = "CHAR" then do
linelen = length( line.i )
if linelen >= cutpos then do
selectwhen cutlen = 0 then do
msg = substr( line.i, cutpos )
call Output endwhen cutlen > 0 then do
if linelen < cuttot then do
msg = substr( line.i, cutpos )
call Output endelse do
msg = substr( line.i, cutpos, cutlen )
call Output end endotherwise call Syntax
end endelse do
msg = ""
call Output end endif cuttype = "WORD" & delimiter = " " then do
linelen = words( line.i )
if linelen >= cutpos then do
selectwhen cutlen = 0 then do
msg = subword( line.i, cutpos )
call Output endwhen cutlen > 0 then do
if linelen < cuttot then do
msg = subword( line.i, cutpos )
call Output endelse do
msg = subword( line.i, cutpos, cutlen )
call Output end endotherwise call Syntax
end endelse do
msg = ""
call Output end endif cuttype = "WORD" & delimiter <> " " then do
string = line.idlen = length( delimiter )
do j = 1 by 1 until string = ""
interpret 'parse '||case||' value string with word.'||j||'"'||delimiter||'"string'
word.0 = j
endlinelen = word.0
line = word.cutpos
if linelen > cutpos then do j = cutpos + 1 by 1 to linelen
line = line||delimiter||word.j
endif linelen >= cutpos then do
selectwhen cutlen = 0 then msg = line
when cutlen > 0 then do
if linelen < cuttot then do
msg = line endelse do
dpos = 0
do j = 1 to cutlen
dpos = pos( delimiter, line, dpos + dlen )
endmsg = substr( line, 1, dpos )
end endotherwise call Syntax
end call Output endelse do
msg = ""
call Output end endendEXITOutput:if skip = 0 | strip( msg ) <> "" then do
if xcommand <> "" then do
call value variable, msg, "OS2ENVIRONMENT"
address CMD "@CMD /C "||xcommand
endelse do
say msg end endreturnSyntax: procedure
call beep 220, 240
saysay " CUT, Version 2.01 for OS/2"
say " (C) 1998 - 2000, Rob van der Woude"
say " http://www.robvanderwoude.com"
saysay " Usage: <any_command> | CUT <options>"
saysay " Options: Function: Dependency"
say " __________________________________________________________________________"
saysay " -C:<column_number> Parse by Columns or Characters"
say ' -D:"<delimiter>" Delimiter character or string -F'
say " -F:<field_number> Parse by Fields or words"
say " -I Case Insensitive delimiter (should -D"
say " be the first or last parameter)"
say " -L:<string_length> Number of characters to display -C"
say " or -L:<fields> Number of fields (words) to display -F"
say " -V:<variable_name> Save last result in environment variable"
saysay " Examples:"
saysay " ECHO 1234567890 | CUT -C:4"
saysay ' VER | TIME | CUT -F:2 -D:":" -S -V:TIME -X:TEST.CMD'
say " (TEST.CMD should contain one line: ECHO Time is %TIME%)"
sayEXIT 1
endpage last modified: 2025-10-11; loaded in 0.0069 seconds