diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js
index 1b068644..da0c9f0a 100755
--- a/src/core/config/Categories.js
+++ b/src/core/config/Categories.js
@@ -162,6 +162,8 @@ const Categories = [
"Unique",
"Split",
"Filter",
+ "Head",
+ "Tail",
"Count occurrences",
"Expand alphabet range",
"Parse escaped string",
diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js
index 777f21f3..ca6bdbbd 100755
--- a/src/core/config/OperationConfig.js
+++ b/src/core/config/OperationConfig.js
@@ -3201,9 +3201,9 @@ const OperationConfig = {
description: [
"Like the UNIX head utility.",
"
",
- "Gets the first $Number of lines.",
+ "Gets the first n lines.",
"
",
- "Optionally you can select all but the last $Number of lines.",
+ "You can select all but the last n lines by entering a negative value for n.",
"
",
"The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.",
].join("\n"),
@@ -3221,20 +3221,15 @@ const OperationConfig = {
type: "number",
value: 10,
},
- {
- name: "All but last $Number of lines",
- type: "boolean",
- value: false,
- },
]
},
"Tail": {
description: [
"Like the UNIX tail utility.",
"
",
- "Gets the last $Number of lines.",
+ "Gets the last n lines.",
"
",
- "Optionally you can select all lines after line $Number.",
+ "Optionally you can select all lines after line n by entering a negative value for n.",
"
",
"The delimiter can be changed so that instead of lines, fields (i.e. commas) are selected instead.",
].join("\n"),
@@ -3252,11 +3247,6 @@ const OperationConfig = {
type: "number",
value: 10,
},
- {
- name: "Start from line $Number",
- type: "boolean",
- value: false,
- },
]
},
};
diff --git a/src/core/operations/StrUtils.js b/src/core/operations/StrUtils.js
index 4ba0b18e..00d2c561 100755
--- a/src/core/operations/StrUtils.js
+++ b/src/core/operations/StrUtils.js
@@ -460,6 +460,62 @@ const StrUtils = {
},
+ /**
+ * Head lines operation.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runHead: function(input, args) {
+ let delimiter = args[0],
+ number = args[1];
+
+ delimiter = Utils.charRep[delimiter];
+ let splitInput = input.split(delimiter);
+
+ return splitInput
+ .filter((line, lineIndex) => {
+ lineIndex += 1;
+
+ if (number < 0) {
+ return lineIndex <= splitInput.length + number;
+ } else {
+ return lineIndex <= number;
+ }
+ })
+ .join(delimiter);
+ },
+
+
+ /**
+ * Tail lines operation.
+ *
+ * @param {string} input
+ * @param {Object[]} args
+ * @returns {string}
+ */
+ runTail: function(input, args) {
+ let delimiter = args[0],
+ number = args[1];
+
+ delimiter = Utils.charRep[delimiter];
+ let splitInput = input.split(delimiter);
+
+ return splitInput
+ .filter((line, lineIndex) => {
+ lineIndex += 1;
+
+ if (number < 0) {
+ return lineIndex > -number;
+ } else {
+ return lineIndex > splitInput.length - number;
+ }
+ })
+ .join(delimiter);
+ },
+
+
/**
* Adds HTML highlights to matches within a string.
*
@@ -537,61 +593,6 @@ const StrUtils = {
return output;
},
- /**
- * Head lines operation.
- *
- * @param {string} input
- * @param {Object[]} args
- * @returns {string}
- */
- runHead: function(input, args) {
- let delimiter = args[0],
- number = args[1],
- allBut = args[2];
-
- delimiter = Utils.charRep[delimiter];
- let splitInput = input.split(delimiter);
-
- return splitInput
- .filter((line, lineIndex) => {
- lineIndex += 1;
-
- if (allBut) {
- return lineIndex <= splitInput.length - number;
- } else {
- return lineIndex <= number;
- }
- })
- .join(delimiter);
- },
-
- /**
- * Tail lines operation.
- *
- * @param {string} input
- * @param {Object[]} args
- * @returns {string}
- */
- runTail: function(input, args) {
- let delimiter = args[0],
- number = args[1],
- allBut = args[2];
-
- delimiter = Utils.charRep[delimiter];
- let splitInput = input.split(delimiter);
-
- return splitInput
- .filter((line, lineIndex) => {
- lineIndex += 1;
-
- if (allBut) {
- return lineIndex >= number;
- } else {
- return lineIndex > splitInput.length - number;
- }
- })
- .join(delimiter);
- },
};
export default StrUtils;