Slicing the output of grep in bash
I'm trying to read a line of text in bash using grep
, piped to tail
to get the final line of the file, and then slice the first three "words" (i.e. dividing them using space) of that line as elements of an array.
It works fine if I try to, e.g. loop over the elements in the output using a for
loop, and I get the list of elements I want:
foo=$(grep select file.txt | tail -n 1)
echo $foo
0.47331 5.11188 13.1615 # select
for x in $foo; do echo $x; done
0.47331
5.11188
13.1615
#
select
Exactly what I want it to do!
But if I try to get out an array with the first three elements of foo
, I cannot get it to work:
echo "${foo[@]:0:2}"
0.47331 5.11188 13.1615 # select 4.95294 13.5177
What's particularly weird is that those last two values at the end of the line are actually two values from the first line containing select
in file.txt
(and not even the first two items on that line, but the second and third!), so they shouldn't even be part of foo
at all...
Similarly, if I try and simply slice a single "word" from foo
, I get a weird output:
echo "${foo[0]}"
0.47331 5.11188 13.1615 # select
echo "${foo[1]}"
4.95294
(Again, that last value is a value that shouldn't, as I best understand it, even be in foo
, it's the second item on the first line with select
in file.txt
...).
I need to understand what is going on, and how to get out the output I want, namely an array 0.47331 5.11188 13.1615
.
bash grep array tail
add a comment |
I'm trying to read a line of text in bash using grep
, piped to tail
to get the final line of the file, and then slice the first three "words" (i.e. dividing them using space) of that line as elements of an array.
It works fine if I try to, e.g. loop over the elements in the output using a for
loop, and I get the list of elements I want:
foo=$(grep select file.txt | tail -n 1)
echo $foo
0.47331 5.11188 13.1615 # select
for x in $foo; do echo $x; done
0.47331
5.11188
13.1615
#
select
Exactly what I want it to do!
But if I try to get out an array with the first three elements of foo
, I cannot get it to work:
echo "${foo[@]:0:2}"
0.47331 5.11188 13.1615 # select 4.95294 13.5177
What's particularly weird is that those last two values at the end of the line are actually two values from the first line containing select
in file.txt
(and not even the first two items on that line, but the second and third!), so they shouldn't even be part of foo
at all...
Similarly, if I try and simply slice a single "word" from foo
, I get a weird output:
echo "${foo[0]}"
0.47331 5.11188 13.1615 # select
echo "${foo[1]}"
4.95294
(Again, that last value is a value that shouldn't, as I best understand it, even be in foo
, it's the second item on the first line with select
in file.txt
...).
I need to understand what is going on, and how to get out the output I want, namely an array 0.47331 5.11188 13.1615
.
bash grep array tail
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
2
Doesfoo=( $(grep select file.txt | tail -n 1) )
solve all your problems?
– Michael Homer
Feb 5 at 8:45
echo "${foo[@]:0:2}"
... you haven't created afoo
array yet, so what did you expect this to do?
– Olorin
Feb 5 at 8:46
add a comment |
I'm trying to read a line of text in bash using grep
, piped to tail
to get the final line of the file, and then slice the first three "words" (i.e. dividing them using space) of that line as elements of an array.
It works fine if I try to, e.g. loop over the elements in the output using a for
loop, and I get the list of elements I want:
foo=$(grep select file.txt | tail -n 1)
echo $foo
0.47331 5.11188 13.1615 # select
for x in $foo; do echo $x; done
0.47331
5.11188
13.1615
#
select
Exactly what I want it to do!
But if I try to get out an array with the first three elements of foo
, I cannot get it to work:
echo "${foo[@]:0:2}"
0.47331 5.11188 13.1615 # select 4.95294 13.5177
What's particularly weird is that those last two values at the end of the line are actually two values from the first line containing select
in file.txt
(and not even the first two items on that line, but the second and third!), so they shouldn't even be part of foo
at all...
Similarly, if I try and simply slice a single "word" from foo
, I get a weird output:
echo "${foo[0]}"
0.47331 5.11188 13.1615 # select
echo "${foo[1]}"
4.95294
(Again, that last value is a value that shouldn't, as I best understand it, even be in foo
, it's the second item on the first line with select
in file.txt
...).
I need to understand what is going on, and how to get out the output I want, namely an array 0.47331 5.11188 13.1615
.
bash grep array tail
I'm trying to read a line of text in bash using grep
, piped to tail
to get the final line of the file, and then slice the first three "words" (i.e. dividing them using space) of that line as elements of an array.
It works fine if I try to, e.g. loop over the elements in the output using a for
loop, and I get the list of elements I want:
foo=$(grep select file.txt | tail -n 1)
echo $foo
0.47331 5.11188 13.1615 # select
for x in $foo; do echo $x; done
0.47331
5.11188
13.1615
#
select
Exactly what I want it to do!
But if I try to get out an array with the first three elements of foo
, I cannot get it to work:
echo "${foo[@]:0:2}"
0.47331 5.11188 13.1615 # select 4.95294 13.5177
What's particularly weird is that those last two values at the end of the line are actually two values from the first line containing select
in file.txt
(and not even the first two items on that line, but the second and third!), so they shouldn't even be part of foo
at all...
Similarly, if I try and simply slice a single "word" from foo
, I get a weird output:
echo "${foo[0]}"
0.47331 5.11188 13.1615 # select
echo "${foo[1]}"
4.95294
(Again, that last value is a value that shouldn't, as I best understand it, even be in foo
, it's the second item on the first line with select
in file.txt
...).
I need to understand what is going on, and how to get out the output I want, namely an array 0.47331 5.11188 13.1615
.
bash grep array tail
bash grep array tail
edited Feb 8 at 3:16
Rui F Ribeiro
41.8k1483142
41.8k1483142
asked Feb 5 at 8:36
Henry BriceHenry Brice
1085
1085
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
2
Doesfoo=( $(grep select file.txt | tail -n 1) )
solve all your problems?
– Michael Homer
Feb 5 at 8:45
echo "${foo[@]:0:2}"
... you haven't created afoo
array yet, so what did you expect this to do?
– Olorin
Feb 5 at 8:46
add a comment |
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
2
Doesfoo=( $(grep select file.txt | tail -n 1) )
solve all your problems?
– Michael Homer
Feb 5 at 8:45
echo "${foo[@]:0:2}"
... you haven't created afoo
array yet, so what did you expect this to do?
– Olorin
Feb 5 at 8:46
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
2
2
Does
foo=( $(grep select file.txt | tail -n 1) )
solve all your problems?– Michael Homer
Feb 5 at 8:45
Does
foo=( $(grep select file.txt | tail -n 1) )
solve all your problems?– Michael Homer
Feb 5 at 8:45
echo "${foo[@]:0:2}"
... you haven't created a foo
array yet, so what did you expect this to do?– Olorin
Feb 5 at 8:46
echo "${foo[@]:0:2}"
... you haven't created a foo
array yet, so what did you expect this to do?– Olorin
Feb 5 at 8:46
add a comment |
2 Answers
2
active
oldest
votes
$foo
isn't an array; it's a string containing several space-separated words. If you want it to be an array, assign it as one:
foo=( $(grep 'select' file.txt | tail -n 1) )
Now you can reference ${foo[0]}
, or the first three elements as ${foo[@]:0:3}
.
Note that ${foo[@]}
will contain all five elements from your last matching line as there's nothing here to extract just the first three elements. You could use foo=("${foo[@]:0:3}")
to chop ${foo[@]}
down to size if you wanted.
Alternatively, if you want to create the array with just the first three elements you can use awk
like this:
foo=( $(awk '/select/ { a=$1; b=$2; c=$3 } END { print a,b,c }' file.txt) )
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be infoo
?
– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given thatfoo
was defined as the output of thegrep
piped totail
, how does the slicing call get the values that are infile.txt
? Or am I wrong, andfoo
actually somehow contains all of thegrep
call, even though thefor
loop doesn't see it?
– Henry Brice
Feb 5 at 10:25
Your$foo
was a string containing the result of yourgrep | tail
. It had five space-separated elements. We can force that as an array with thefoo=( ... )
construct, but it still has five elements. You can pick out the first three with${foo[@]:0:3}
. I've updated my answer to incorporate this.
– roaima
Feb 5 at 11:25
add a comment |
This avoids reading the data into variables:
$ grep -F select file | tail -n 1 | cut -d ' ' -f 1-3
0.47331 5.11188 13.1615
To get the values into an array in bash
, use mapfile
(or readarray
):
$ mapfile -t arr < <( grep -F select file | tail -n 1 | cut -d ' ' -f 1-3 | tr ' ' 'n' )
$ printf 'arr: %sn' "${arr[@]}"
arr: 0.47331
arr: 5.11188
arr: 13.1615
I'm using tr
to change the spaces between the numbers to newlines. That way I don't get a trailing newline character at the end of the last value in the array.
Instead of the awkward grep
+tail
+cut
+tr
pipeline, you could obviously use
awk '/select/ { a=$1; b=$2; c=$3 } END { printf("%sn%sn%sn", a, b, c) }'
or something like it inside the <(...)
process substitution.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498753%2fslicing-the-output-of-grep-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$foo
isn't an array; it's a string containing several space-separated words. If you want it to be an array, assign it as one:
foo=( $(grep 'select' file.txt | tail -n 1) )
Now you can reference ${foo[0]}
, or the first three elements as ${foo[@]:0:3}
.
Note that ${foo[@]}
will contain all five elements from your last matching line as there's nothing here to extract just the first three elements. You could use foo=("${foo[@]:0:3}")
to chop ${foo[@]}
down to size if you wanted.
Alternatively, if you want to create the array with just the first three elements you can use awk
like this:
foo=( $(awk '/select/ { a=$1; b=$2; c=$3 } END { print a,b,c }' file.txt) )
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be infoo
?
– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given thatfoo
was defined as the output of thegrep
piped totail
, how does the slicing call get the values that are infile.txt
? Or am I wrong, andfoo
actually somehow contains all of thegrep
call, even though thefor
loop doesn't see it?
– Henry Brice
Feb 5 at 10:25
Your$foo
was a string containing the result of yourgrep | tail
. It had five space-separated elements. We can force that as an array with thefoo=( ... )
construct, but it still has five elements. You can pick out the first three with${foo[@]:0:3}
. I've updated my answer to incorporate this.
– roaima
Feb 5 at 11:25
add a comment |
$foo
isn't an array; it's a string containing several space-separated words. If you want it to be an array, assign it as one:
foo=( $(grep 'select' file.txt | tail -n 1) )
Now you can reference ${foo[0]}
, or the first three elements as ${foo[@]:0:3}
.
Note that ${foo[@]}
will contain all five elements from your last matching line as there's nothing here to extract just the first three elements. You could use foo=("${foo[@]:0:3}")
to chop ${foo[@]}
down to size if you wanted.
Alternatively, if you want to create the array with just the first three elements you can use awk
like this:
foo=( $(awk '/select/ { a=$1; b=$2; c=$3 } END { print a,b,c }' file.txt) )
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be infoo
?
– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given thatfoo
was defined as the output of thegrep
piped totail
, how does the slicing call get the values that are infile.txt
? Or am I wrong, andfoo
actually somehow contains all of thegrep
call, even though thefor
loop doesn't see it?
– Henry Brice
Feb 5 at 10:25
Your$foo
was a string containing the result of yourgrep | tail
. It had five space-separated elements. We can force that as an array with thefoo=( ... )
construct, but it still has five elements. You can pick out the first three with${foo[@]:0:3}
. I've updated my answer to incorporate this.
– roaima
Feb 5 at 11:25
add a comment |
$foo
isn't an array; it's a string containing several space-separated words. If you want it to be an array, assign it as one:
foo=( $(grep 'select' file.txt | tail -n 1) )
Now you can reference ${foo[0]}
, or the first three elements as ${foo[@]:0:3}
.
Note that ${foo[@]}
will contain all five elements from your last matching line as there's nothing here to extract just the first three elements. You could use foo=("${foo[@]:0:3}")
to chop ${foo[@]}
down to size if you wanted.
Alternatively, if you want to create the array with just the first three elements you can use awk
like this:
foo=( $(awk '/select/ { a=$1; b=$2; c=$3 } END { print a,b,c }' file.txt) )
$foo
isn't an array; it's a string containing several space-separated words. If you want it to be an array, assign it as one:
foo=( $(grep 'select' file.txt | tail -n 1) )
Now you can reference ${foo[0]}
, or the first three elements as ${foo[@]:0:3}
.
Note that ${foo[@]}
will contain all five elements from your last matching line as there's nothing here to extract just the first three elements. You could use foo=("${foo[@]:0:3}")
to chop ${foo[@]}
down to size if you wanted.
Alternatively, if you want to create the array with just the first three elements you can use awk
like this:
foo=( $(awk '/select/ { a=$1; b=$2; c=$3 } END { print a,b,c }' file.txt) )
edited Feb 5 at 11:25
answered Feb 5 at 8:46
roaimaroaima
45.9k758124
45.9k758124
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be infoo
?
– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given thatfoo
was defined as the output of thegrep
piped totail
, how does the slicing call get the values that are infile.txt
? Or am I wrong, andfoo
actually somehow contains all of thegrep
call, even though thefor
loop doesn't see it?
– Henry Brice
Feb 5 at 10:25
Your$foo
was a string containing the result of yourgrep | tail
. It had five space-separated elements. We can force that as an array with thefoo=( ... )
construct, but it still has five elements. You can pick out the first three with${foo[@]:0:3}
. I've updated my answer to incorporate this.
– roaima
Feb 5 at 11:25
add a comment |
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be infoo
?
– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given thatfoo
was defined as the output of thegrep
piped totail
, how does the slicing call get the values that are infile.txt
? Or am I wrong, andfoo
actually somehow contains all of thegrep
call, even though thefor
loop doesn't see it?
– Henry Brice
Feb 5 at 10:25
Your$foo
was a string containing the result of yourgrep | tail
. It had five space-separated elements. We can force that as an array with thefoo=( ... )
construct, but it still has five elements. You can pick out the first three with${foo[@]:0:3}
. I've updated my answer to incorporate this.
– roaima
Feb 5 at 11:25
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be in
foo
?– Henry Brice
Feb 5 at 8:48
Thanks, that does work, and I can then use ${foo[@]:0:3} to get the first three elements. But do you know how the script above is pulling elements that I didn't think would even be in
foo
?– Henry Brice
Feb 5 at 8:48
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
The array is made from all the space-separated elements. There was nothing in your code to pick out just the first three.
– roaima
Feb 5 at 8:52
But given that
foo
was defined as the output of the grep
piped to tail
, how does the slicing call get the values that are in file.txt
? Or am I wrong, and foo
actually somehow contains all of the grep
call, even though the for
loop doesn't see it?– Henry Brice
Feb 5 at 10:25
But given that
foo
was defined as the output of the grep
piped to tail
, how does the slicing call get the values that are in file.txt
? Or am I wrong, and foo
actually somehow contains all of the grep
call, even though the for
loop doesn't see it?– Henry Brice
Feb 5 at 10:25
Your
$foo
was a string containing the result of your grep | tail
. It had five space-separated elements. We can force that as an array with the foo=( ... )
construct, but it still has five elements. You can pick out the first three with ${foo[@]:0:3}
. I've updated my answer to incorporate this.– roaima
Feb 5 at 11:25
Your
$foo
was a string containing the result of your grep | tail
. It had five space-separated elements. We can force that as an array with the foo=( ... )
construct, but it still has five elements. You can pick out the first three with ${foo[@]:0:3}
. I've updated my answer to incorporate this.– roaima
Feb 5 at 11:25
add a comment |
This avoids reading the data into variables:
$ grep -F select file | tail -n 1 | cut -d ' ' -f 1-3
0.47331 5.11188 13.1615
To get the values into an array in bash
, use mapfile
(or readarray
):
$ mapfile -t arr < <( grep -F select file | tail -n 1 | cut -d ' ' -f 1-3 | tr ' ' 'n' )
$ printf 'arr: %sn' "${arr[@]}"
arr: 0.47331
arr: 5.11188
arr: 13.1615
I'm using tr
to change the spaces between the numbers to newlines. That way I don't get a trailing newline character at the end of the last value in the array.
Instead of the awkward grep
+tail
+cut
+tr
pipeline, you could obviously use
awk '/select/ { a=$1; b=$2; c=$3 } END { printf("%sn%sn%sn", a, b, c) }'
or something like it inside the <(...)
process substitution.
add a comment |
This avoids reading the data into variables:
$ grep -F select file | tail -n 1 | cut -d ' ' -f 1-3
0.47331 5.11188 13.1615
To get the values into an array in bash
, use mapfile
(or readarray
):
$ mapfile -t arr < <( grep -F select file | tail -n 1 | cut -d ' ' -f 1-3 | tr ' ' 'n' )
$ printf 'arr: %sn' "${arr[@]}"
arr: 0.47331
arr: 5.11188
arr: 13.1615
I'm using tr
to change the spaces between the numbers to newlines. That way I don't get a trailing newline character at the end of the last value in the array.
Instead of the awkward grep
+tail
+cut
+tr
pipeline, you could obviously use
awk '/select/ { a=$1; b=$2; c=$3 } END { printf("%sn%sn%sn", a, b, c) }'
or something like it inside the <(...)
process substitution.
add a comment |
This avoids reading the data into variables:
$ grep -F select file | tail -n 1 | cut -d ' ' -f 1-3
0.47331 5.11188 13.1615
To get the values into an array in bash
, use mapfile
(or readarray
):
$ mapfile -t arr < <( grep -F select file | tail -n 1 | cut -d ' ' -f 1-3 | tr ' ' 'n' )
$ printf 'arr: %sn' "${arr[@]}"
arr: 0.47331
arr: 5.11188
arr: 13.1615
I'm using tr
to change the spaces between the numbers to newlines. That way I don't get a trailing newline character at the end of the last value in the array.
Instead of the awkward grep
+tail
+cut
+tr
pipeline, you could obviously use
awk '/select/ { a=$1; b=$2; c=$3 } END { printf("%sn%sn%sn", a, b, c) }'
or something like it inside the <(...)
process substitution.
This avoids reading the data into variables:
$ grep -F select file | tail -n 1 | cut -d ' ' -f 1-3
0.47331 5.11188 13.1615
To get the values into an array in bash
, use mapfile
(or readarray
):
$ mapfile -t arr < <( grep -F select file | tail -n 1 | cut -d ' ' -f 1-3 | tr ' ' 'n' )
$ printf 'arr: %sn' "${arr[@]}"
arr: 0.47331
arr: 5.11188
arr: 13.1615
I'm using tr
to change the spaces between the numbers to newlines. That way I don't get a trailing newline character at the end of the last value in the array.
Instead of the awkward grep
+tail
+cut
+tr
pipeline, you could obviously use
awk '/select/ { a=$1; b=$2; c=$3 } END { printf("%sn%sn%sn", a, b, c) }'
or something like it inside the <(...)
process substitution.
edited Feb 5 at 11:44
answered Feb 5 at 11:38
Kusalananda♦Kusalananda
138k17258426
138k17258426
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498753%2fslicing-the-output-of-grep-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if you want us to help, please could you provide a simple example of your issue, with input/output/expected output and describe what is not working simply ?
– Kiwy
Feb 5 at 8:40
2
Does
foo=( $(grep select file.txt | tail -n 1) )
solve all your problems?– Michael Homer
Feb 5 at 8:45
echo "${foo[@]:0:2}"
... you haven't created afoo
array yet, so what did you expect this to do?– Olorin
Feb 5 at 8:46