FIL. - File-Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Filesystem-Commands > FIL. - File-Commands >

FIL. - File-Commands

FIL.Replace in large File

Previous Top Next


MiniRobotLanguage (MRL)

 

FIL.Replace in large File

If Result available

 

 

Intention

 

The FIL.Replace in large File command is a powerful tool designed to handle string replacement operations in large files.
This command is particularly useful when dealing with files that are too large to be loaded into memory all at once.

 

Unlike its counterpart, FIL.Replace in File, which loads the entire file into memory for string replacement,

FIL.Replace in large File operates in a more memory-efficient manner.

It works by processing the file in overlapping chunks of 100KB, allowing it to handle very large files that would otherwise exceed memory limits.

 

The FIL.Replace in large File command is ideal for scenarios where you need to perform string replacement operations on very large files, especially when these files cannot be loaded into memory all at once.

For instance, consider a scenario where you have a large log file (several GBs in size) and you need to replace all occurrences of a specific error code with a more descriptive message.

Loading such a large file into memory could be impractical or impossible due to memory constraints. This is where FIL.Replace in large File comes in handy.

 

Here's a sample usage:

 

FIL.Replace in large Files|C:\Logs\largeLogFile.log|ERROR_123|Database connection failed|-1|1

 

In this example, the command will start from the end of the file and replace all case-sensitive occurrences of ERROR_123 with Database connection failed in the file largeLogFile.log.

Remember, if the file is small enough to be loaded into memory, consider using FIL.Replace in Files for a potentially faster operation.

However, for handling larger files, FIL.Replace in large File is the recommended choice.

 

Syntax

 

 

FIL.Replace in large File|P1|P2|P3[|P4][|P5][|P6]

FIL.ril|P1|P2|P3[|P4][|P5][|P6]

 

 

Parameter Explanation

 

P1: This is the filename or path of the file you want to modify. It should be a string that points to a valid file on your system.

P2: This is the string you want to replace in the file. It should be a string that exists in your file.

P3: This is the string you want to replace P2 with. It can be any string.

P4: This is the position in the file where you want to start the replace operation. If it's positive, it represents the position from the start of the file. If it's negative, it represents the position from the end of the file. If it's omitted or zero, the replace operation starts from the beginning of the file.

P5: This is a set of flags that control the behavior of the replace operation. It's a bitwise OR of the following options:

1: If this bit is set, the search for P2 is case sensitive.

2: If this bit is set, P2 is only replaced if it's a whole word (i.e., surrounded by spaces or at the start/end of the file).

4: If this bit is set, only the first occurrence of P2 is replaced. If it's not set, all occurrences of P2 are replaced.

P6: This is a variable that will contain the result of the operation as follows:    

o0: The operation was successful.

o1: There was an error opening the file for reading.

o2: There was an error opening the file for writing.

o3: There was an error during the file copy operation.

o4: There was an error during the file rename operation.

o5: There was an error during the file delete operation.

o6: There was an error due to insufficient disk space.

 

These return values provide detailed information about the outcome of the operation, allowing for precise error handling and troubleshooting.

 

 

 

 

Example

 

'***********************************

'

'***********************************

 

 

 

 

 

Remarks

 

-

 

 

Limitations:

 

-

 

 

See also:

 

 

    Split File

    Join File

    OPT. - Optional Settings

    GEC. - Get Encryption

    RMD. - Remove-Directory

    ATF - Append-to-File

    CFF. - Copy-From-File

    CTF - Copy-To-File

    COP. - Copy File

    SHF. - Shell-File-Operation

    MDF. - Make-Direktory-File

    MKD. - Make-Directory

    GLC. - Get-Line-Count

    IEF. / NEF. - If - exist - File

    LFF - Line-From-File

    WFF. - Wait-For-File

    REN. - Rename File/Dir