Text file and manipulation
Easy-to-use functions to get info about or to manipulate text files.
Functions in this category
Details
addLine
|
Syntax: addLine <FILENAME> <STRING>
|
FILENAME:
|
A filename.
|
STRING:
|
The line to add.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Add STRING to FILENAME as a new newline. If the file doesn't already
end with a newline, it will be added.
|
addSectionLine
|
Syntax: addSectionLine <FILENAME> <SECTION>
<REPLACE> <MATCH>
|
MATCH:
|
Text to match against in the defined section text.
|
SECTION:
|
Text section to modify or add text line.
|
REPLACE:
|
Text to be added or replaced against the matched text line.
|
FILENAME:
|
File to update.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Add or replace a text line to a named section of an INI-style file.
Filename or section marker will be added if either is not present. If
MATCH is not given the REPLACE text will be added.
|
countFileLines
|
Syntax: countFileLines <FILENAME>
|
FILE:
|
a text file path
|
Outputs:
|
The number of lines in FILE
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Calculate how many lines FILE has.
See also: countStringLines()
|
endsWithNewline
|
Syntax: endsWithNewline <FILENAME>
|
FILENAME:
|
A filename.
|
Returns:
|
0 on true, 1 on false.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Finds out if the last byte in file FILENAME is a newline (\n).
|
getSection
|
Syntax: getSection <FILENAME> <SECTION>
|
SECTION:
|
The name of a section (excluding brackets).
|
INIFILE:
|
The filename of a INI file.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Extracts the contents of an INI file section.
|
getKey
|
Syntax: getKey [<INPUT>] <KEY>
|
KEY:
|
A string.
|
INPUT:
|
A string, or - indicating stdin. If not specified, - is used
|
Outputs:
|
The KEY's value.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
getKey searches the input text for a line of the form "KEY: VALUE", and
outputs VALUE.
|
Example:
cat <<EOF | getKey - name
name: keymaker
age: 27
occupation: making keys
EOF
|
getSectionKey
|
Syntax: getSectionKey <FILENAME> <SECTION>
<KEY>
|
KEY:
|
piece of data to find in SECTION text.
|
SECTION:
|
name of section in the FILE, excluding brackets.
|
Output:
|
if KEY exists in SECTION, then the data is printed in a
localized language value or defaults to english value.
|
FILENAME:
|
INI-type file from which to read [SECTION] text
|
Returns:
|
1 if KEY does not exist in SECTION text.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Function will print the KEY value from a FILENAME from within its
SECTION text. If KEY is localized, then the localized value will be
printed.
|
Example:
skeleton_file=`_locateSkeleton "$root_name"`
displayname=`getSectionKey "$skeleton_file" "Meta" "DisplayName"`
|
removeLine
|
Syntax: removeLine <FILENAME> <STRING>
|
FILENAME:
|
A filename.
|
STRING:
|
The line to remove.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Look for lines that equals STRING in a text file and removes them.
|
removeSectionLine
|
Syntax: removeSectionLine <INIFILE> <SECTION>
<MATCH>
|
MATCH:
|
The text to match against.
|
SECTION:
|
The name of a section (excluding brackets).
|
INIFILE:
|
The INI file to update.
|
Since:
|
1.0
|
Deprecated:
|
N/A
|
|
Remove a text line to a named section of a INI file.
|
Example:
removeSectionLine "hello.ini" "Foo" "hello=1"
|