Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
IMPORT STD;
|
||||
RemoveLines(logicalfile, startline, numlines) := FUNCTIONMACRO
|
||||
EndLine := startline + numlines - 1;
|
||||
RecCnt := COUNT(logicalfile);
|
||||
Res := logicalfile[1..startline-1] + logicalfile[endline+1..];
|
||||
RETURN WHEN(IF(RecCnt < EndLine,logicalfile,Res),
|
||||
IF(RecCnt < EndLine,STD.System.Log.addWorkunitWarning('Attempted removal past end of file-removal ignored')));
|
||||
ENDMACRO;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
MyFile := DATASET(100,TRANSFORM({UNSIGNED1 RecID},SELF.RecID := COUNTER));
|
||||
RemoveLines(MyFile,3,10);
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub removeLines(fileName As String, startLine As UInteger, numLines As UInteger)
|
||||
If startLine = 0 Then
|
||||
Print "Starting line must be more than zero"
|
||||
Return
|
||||
End If
|
||||
If numLines = 0 Then
|
||||
Print "No lines to remove"
|
||||
Return
|
||||
End If
|
||||
Dim fileNum As Integer = FreeFile
|
||||
Open fileName For Input As #fileNum
|
||||
If err > 0 Then
|
||||
Print "File could not be opened"
|
||||
Return
|
||||
End If
|
||||
Dim tempFileName As String = "temp_" + fileName
|
||||
Dim fileNum2 As Integer = FreeFile
|
||||
Open tempFileName For Output As #fileNum2
|
||||
Dim count As Integer = 0
|
||||
Dim ln As String
|
||||
Dim endLine As UInteger = startLine + numLines - 1
|
||||
While Not Eof(fileNum)
|
||||
Input #fileNum, ln
|
||||
count += 1
|
||||
If count >= startLine AndAlso count <= endLine Then Continue While
|
||||
Print #fileNum2, ln
|
||||
Wend
|
||||
|
||||
If count < startLine Then
|
||||
Print "No lines were removed as starting line was beyond end of file"
|
||||
Print
|
||||
ElseIf count < endLine Then
|
||||
Print "Only "; count - startLine + 1; " line(s) were removed as not enough lines to remove more"
|
||||
Print
|
||||
Else
|
||||
Print Str(numLines); " line(s) were removed"
|
||||
Print
|
||||
End If
|
||||
Close #fileNum : Close #fileNum2
|
||||
Kill(fileName)
|
||||
Name (tempFileName, fileName)
|
||||
End Sub
|
||||
|
||||
removeLines("foobar.txt", 2, 2)
|
||||
removeLines("foobar.txt", 5, 2)
|
||||
removeLines("foobar.txt", 3, 4)
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
local(
|
||||
orgfilename = $argv -> second,
|
||||
file = file(#orgfilename),
|
||||
regexp = regexp(-find = `(?m)$`),
|
||||
content = #regexp -> split(-input = #file -> readstring) -> asarray,
|
||||
start = integer($argv -> get(3) || 1),
|
||||
range = integer($argv -> get(4) || 1)
|
||||
)
|
||||
stdout(#content)
|
||||
#file -> copyto(#orgfilename + '.org')
|
||||
|
||||
fail_if(#content -> size < (#start + #range), -1, 'Not that many rows in the file')
|
||||
|
||||
#content -> remove(#start, #range)
|
||||
|
||||
#file = file(#orgfilename)
|
||||
#file -> opentruncate
|
||||
#file -> dowithclose => {
|
||||
#file -> writestring(#content -> join(''))
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
./removelines textfile.txt 2 2
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
: removeLines(filename, startLine, numLines)
|
||||
| line b endLine |
|
||||
ListBuffer new ->b
|
||||
startLine numLines + 1 - ->endLine
|
||||
|
||||
0 File new(filename) forEach: line [
|
||||
1+ dup between(startLine, endLine) ifFalse: [ b add(line) continue ]
|
||||
numLines 1- ->numLines
|
||||
]
|
||||
drop numLines 0 == ifFalse: [ "Error : Removing lines beyond end of file" println return ]
|
||||
|
||||
File new(filename) dup open(File.WRITE) b apply(#[ << dup cr ]) close ;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
cStr = read("C:\Ring\bin\filename.txt")
|
||||
aList = str2list(cStr)
|
||||
see aList + nl
|
||||
lineStart = 3
|
||||
lineCount = 5
|
||||
num = -1
|
||||
for n = lineStart to lineStart+lineCount-1
|
||||
num += 1
|
||||
del(aList,n-num)
|
||||
next
|
||||
cStr = list2str(aList)
|
||||
see cStr + nl
|
||||
write("C:\Ring\bin\filename.txt",cStr)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
func remove_lines(file, beg, len) {
|
||||
var lines = file.open_r.lines;
|
||||
lines.splice(beg, len).len == len || warn "Too few lines";
|
||||
file.open_w.print(lines.join)
|
||||
}
|
||||
|
||||
remove_lines(File(__FILE__), 2, 3);
|
||||
|
|
@ -0,0 +1 @@
|
|||
jq -s -R -r --arg start START --arg number NUMBER -f remove.jq INFILE
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Counting the first line in the file as line 1,
|
||||
# attempt to remove "number" lines from line number "start" onwards:
|
||||
def remove_lines(start; number):
|
||||
(start+number - 1) as $max
|
||||
| reduce split("\n")[] as $line
|
||||
( [0, []];
|
||||
.[0] += 1
|
||||
| .[0] as $i
|
||||
| if start <= $i and $i <= $max then . else .[1] += [$line] end)
|
||||
| .[0] as $count
|
||||
| .[1]
|
||||
| join("\n")
|
||||
| (if $count < $max then "WARNING: there are only \($count) lines" else empty end), .;
|
||||
|
||||
remove_lines($start|tonumber; $number|tonumber)
|
||||
|
|
@ -0,0 +1 @@
|
|||
jq -n -R -r --arg start 1 --arg number 2 -f Remove_lines_from_a_file.jq input.txt
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Counting the first line in the file as line 1, attempt to remove "number" lines from line
|
||||
# number "start" onwards:
|
||||
def remove_lines_streaming(start; number):
|
||||
(start+number - 1) as $max
|
||||
# In the following line, null will serve to signal EOF so that the warning can be emitted.
|
||||
| foreach (inputs,null) as $line
|
||||
( 0;
|
||||
. += 1;
|
||||
if $line == null then # EOF
|
||||
if . <= $max then "WARNING: there were only \(.) lines" else empty end
|
||||
elif start <= . and . <= $max then empty
|
||||
else $line
|
||||
end) ;
|
||||
|
||||
remove_lines_streaming($start|tonumber; $number|tonumber)
|
||||
Loading…
Add table
Add a link
Reference in a new issue