Bash add regex values to an array
I am trying to write a bash script that will take in a file and look for all values matching a regular expression, and then add those to an array.
As a first step, I wrote a script that adds all lines in the log file to an array, and echoes them. Then, I tried editing that script to search for the regular expression in the log file, which is where I got a tremendous amount of errors.
What I am trying to do is grab the value inside the brackets of the log file. Some lines in the log file contain a syntax like [23423234 s] which is a time stamp. I want to grab the values (digits, space, and the "s") inside the brackets( but not the brackets!) and add those values to an array.
My initial script is below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
array+=("$line")
done <"$1"
getArray "testlog.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
The log I am looking at looks like this:
[1542053213 s] Starting Program:
-----------------------------------------
[1542053213 s] PROGRAM ERROR
ERRHAND: 1033
ERRHAND: 233545
ERRHAND: 1
[1542053213 s] Program completed!
[1542053213 s] Config File complete. Stopping!
What I am aiming to do is do something with the following pseudocode:
For each line in file
regex = [dws]
if line matches regex
add to array
for each item in array
echo item
Currently, I have edited my script to look like below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
if [[$line =~ [dws]; then
array+=("$line");
fi
done <"$1"
getArray "log.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
But whenever I run it, I get the following set of errors:
[jm@local Home]$ ./Parser.sh
STARTING SCRIPT
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[-----------------------------------------: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[: command not found
./Parser.sh: line 9: [[[1542053213: command not found
DONE SCRIPT
Any advice would be greatly appreciated. I have tried looking at other posts but none have been able to really address my problem, which is creating a proper regex for the [2342323 s] pattern, and then adding that to an array. TiA
regex bash shell
|
show 1 more comment
I am trying to write a bash script that will take in a file and look for all values matching a regular expression, and then add those to an array.
As a first step, I wrote a script that adds all lines in the log file to an array, and echoes them. Then, I tried editing that script to search for the regular expression in the log file, which is where I got a tremendous amount of errors.
What I am trying to do is grab the value inside the brackets of the log file. Some lines in the log file contain a syntax like [23423234 s] which is a time stamp. I want to grab the values (digits, space, and the "s") inside the brackets( but not the brackets!) and add those values to an array.
My initial script is below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
array+=("$line")
done <"$1"
getArray "testlog.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
The log I am looking at looks like this:
[1542053213 s] Starting Program:
-----------------------------------------
[1542053213 s] PROGRAM ERROR
ERRHAND: 1033
ERRHAND: 233545
ERRHAND: 1
[1542053213 s] Program completed!
[1542053213 s] Config File complete. Stopping!
What I am aiming to do is do something with the following pseudocode:
For each line in file
regex = [dws]
if line matches regex
add to array
for each item in array
echo item
Currently, I have edited my script to look like below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
if [[$line =~ [dws]; then
array+=("$line");
fi
done <"$1"
getArray "log.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
But whenever I run it, I get the following set of errors:
[jm@local Home]$ ./Parser.sh
STARTING SCRIPT
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[-----------------------------------------: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[: command not found
./Parser.sh: line 9: [[[1542053213: command not found
DONE SCRIPT
Any advice would be greatly appreciated. I have tried looking at other posts but none have been able to really address my problem, which is creating a proper regex for the [2342323 s] pattern, and then adding that to an array. TiA
regex bash shell
if [[$line =~ [dws]; then
should be:if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Yes I knew that regex is wrong but it is equivalent of what you used[dws]
. I need more details from you about regex to suggest you the correct one.
– anubhava
Nov 13 '18 at 22:00
Issed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?
– Paul Hodges
Nov 13 '18 at 22:00
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05
|
show 1 more comment
I am trying to write a bash script that will take in a file and look for all values matching a regular expression, and then add those to an array.
As a first step, I wrote a script that adds all lines in the log file to an array, and echoes them. Then, I tried editing that script to search for the regular expression in the log file, which is where I got a tremendous amount of errors.
What I am trying to do is grab the value inside the brackets of the log file. Some lines in the log file contain a syntax like [23423234 s] which is a time stamp. I want to grab the values (digits, space, and the "s") inside the brackets( but not the brackets!) and add those values to an array.
My initial script is below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
array+=("$line")
done <"$1"
getArray "testlog.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
The log I am looking at looks like this:
[1542053213 s] Starting Program:
-----------------------------------------
[1542053213 s] PROGRAM ERROR
ERRHAND: 1033
ERRHAND: 233545
ERRHAND: 1
[1542053213 s] Program completed!
[1542053213 s] Config File complete. Stopping!
What I am aiming to do is do something with the following pseudocode:
For each line in file
regex = [dws]
if line matches regex
add to array
for each item in array
echo item
Currently, I have edited my script to look like below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
if [[$line =~ [dws]; then
array+=("$line");
fi
done <"$1"
getArray "log.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
But whenever I run it, I get the following set of errors:
[jm@local Home]$ ./Parser.sh
STARTING SCRIPT
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[-----------------------------------------: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[: command not found
./Parser.sh: line 9: [[[1542053213: command not found
DONE SCRIPT
Any advice would be greatly appreciated. I have tried looking at other posts but none have been able to really address my problem, which is creating a proper regex for the [2342323 s] pattern, and then adding that to an array. TiA
regex bash shell
I am trying to write a bash script that will take in a file and look for all values matching a regular expression, and then add those to an array.
As a first step, I wrote a script that adds all lines in the log file to an array, and echoes them. Then, I tried editing that script to search for the regular expression in the log file, which is where I got a tremendous amount of errors.
What I am trying to do is grab the value inside the brackets of the log file. Some lines in the log file contain a syntax like [23423234 s] which is a time stamp. I want to grab the values (digits, space, and the "s") inside the brackets( but not the brackets!) and add those values to an array.
My initial script is below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
array+=("$line")
done <"$1"
getArray "testlog.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
The log I am looking at looks like this:
[1542053213 s] Starting Program:
-----------------------------------------
[1542053213 s] PROGRAM ERROR
ERRHAND: 1033
ERRHAND: 233545
ERRHAND: 1
[1542053213 s] Program completed!
[1542053213 s] Config File complete. Stopping!
What I am aiming to do is do something with the following pseudocode:
For each line in file
regex = [dws]
if line matches regex
add to array
for each item in array
echo item
Currently, I have edited my script to look like below:
#!/bin/bash
echo "STARTING SCRIPT"
getArray()
array=()
while IFS= read -r line
do
if [[$line =~ [dws]; then
array+=("$line");
fi
done <"$1"
getArray "log.txt"
for e in "$array[@]"
do
echo "$e"
done
echo "DONE SCRIPT"
But whenever I run it, I get the following set of errors:
[jm@local Home]$ ./Parser.sh
STARTING SCRIPT
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[-----------------------------------------: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[ERRHAND:: command not found
./Parser.sh: line 9: [[[1542053213: command not found
./Parser.sh: line 9: [[: command not found
./Parser.sh: line 9: [[[1542053213: command not found
DONE SCRIPT
Any advice would be greatly appreciated. I have tried looking at other posts but none have been able to really address my problem, which is creating a proper regex for the [2342323 s] pattern, and then adding that to an array. TiA
regex bash shell
regex bash shell
edited Nov 13 '18 at 22:04
Ulrich Eckhardt
12.7k11737
12.7k11737
asked Nov 13 '18 at 21:51
Jerry M.Jerry M.
6361622
6361622
if [[$line =~ [dws]; then
should be:if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Yes I knew that regex is wrong but it is equivalent of what you used[dws]
. I need more details from you about regex to suggest you the correct one.
– anubhava
Nov 13 '18 at 22:00
Issed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?
– Paul Hodges
Nov 13 '18 at 22:00
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05
|
show 1 more comment
if [[$line =~ [dws]; then
should be:if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Yes I knew that regex is wrong but it is equivalent of what you used[dws]
. I need more details from you about regex to suggest you the correct one.
– anubhava
Nov 13 '18 at 22:00
Issed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?
– Paul Hodges
Nov 13 '18 at 22:00
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05
if [[$line =~ [dws]; then
should be: if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
if [[$line =~ [dws]; then
should be: if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Yes I knew that regex is wrong but it is equivalent of what you used
[dws]
. I need more details from you about regex to suggest you the correct one.– anubhava
Nov 13 '18 at 22:00
Yes I knew that regex is wrong but it is equivalent of what you used
[dws]
. I need more details from you about regex to suggest you the correct one.– anubhava
Nov 13 '18 at 22:00
Is
sed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?– Paul Hodges
Nov 13 '18 at 22:00
Is
sed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?– Paul Hodges
Nov 13 '18 at 22:00
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05
|
show 1 more comment
1 Answer
1
active
oldest
votes
As pointed out in the comments
if [[
is missing its closing]]
.- In a regex
[
is not a literal, but starts a character group. To match something like[1234 s]
you have to write[[0-9]* s]
.
To extract just the number 1234
from [1234 s]
you can use tr
, sed
, perl -P
, or a second grep -o
.
Overall, your script seems way too complicated. You can drastically simplify it. Replace the for
loop by mapfile
and use grep -o
to extract matches. You can replace your whole script with this
mapfile -t array < <(grep -o '[[0-9]* s]' logfile | tr -d ' s')
printf '%sn' "$array[@]"
Note that if you only want to print the matches then you don't need an array. Just the grep
part would be sufficient:
grep -o '[[0-9]* s]' logfile | tr -d ' s'
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53290049%2fbash-add-regex-values-to-an-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As pointed out in the comments
if [[
is missing its closing]]
.- In a regex
[
is not a literal, but starts a character group. To match something like[1234 s]
you have to write[[0-9]* s]
.
To extract just the number 1234
from [1234 s]
you can use tr
, sed
, perl -P
, or a second grep -o
.
Overall, your script seems way too complicated. You can drastically simplify it. Replace the for
loop by mapfile
and use grep -o
to extract matches. You can replace your whole script with this
mapfile -t array < <(grep -o '[[0-9]* s]' logfile | tr -d ' s')
printf '%sn' "$array[@]"
Note that if you only want to print the matches then you don't need an array. Just the grep
part would be sufficient:
grep -o '[[0-9]* s]' logfile | tr -d ' s'
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
add a comment |
As pointed out in the comments
if [[
is missing its closing]]
.- In a regex
[
is not a literal, but starts a character group. To match something like[1234 s]
you have to write[[0-9]* s]
.
To extract just the number 1234
from [1234 s]
you can use tr
, sed
, perl -P
, or a second grep -o
.
Overall, your script seems way too complicated. You can drastically simplify it. Replace the for
loop by mapfile
and use grep -o
to extract matches. You can replace your whole script with this
mapfile -t array < <(grep -o '[[0-9]* s]' logfile | tr -d ' s')
printf '%sn' "$array[@]"
Note that if you only want to print the matches then you don't need an array. Just the grep
part would be sufficient:
grep -o '[[0-9]* s]' logfile | tr -d ' s'
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
add a comment |
As pointed out in the comments
if [[
is missing its closing]]
.- In a regex
[
is not a literal, but starts a character group. To match something like[1234 s]
you have to write[[0-9]* s]
.
To extract just the number 1234
from [1234 s]
you can use tr
, sed
, perl -P
, or a second grep -o
.
Overall, your script seems way too complicated. You can drastically simplify it. Replace the for
loop by mapfile
and use grep -o
to extract matches. You can replace your whole script with this
mapfile -t array < <(grep -o '[[0-9]* s]' logfile | tr -d ' s')
printf '%sn' "$array[@]"
Note that if you only want to print the matches then you don't need an array. Just the grep
part would be sufficient:
grep -o '[[0-9]* s]' logfile | tr -d ' s'
As pointed out in the comments
if [[
is missing its closing]]
.- In a regex
[
is not a literal, but starts a character group. To match something like[1234 s]
you have to write[[0-9]* s]
.
To extract just the number 1234
from [1234 s]
you can use tr
, sed
, perl -P
, or a second grep -o
.
Overall, your script seems way too complicated. You can drastically simplify it. Replace the for
loop by mapfile
and use grep -o
to extract matches. You can replace your whole script with this
mapfile -t array < <(grep -o '[[0-9]* s]' logfile | tr -d ' s')
printf '%sn' "$array[@]"
Note that if you only want to print the matches then you don't need an array. Just the grep
part would be sufficient:
grep -o '[[0-9]* s]' logfile | tr -d ' s'
edited Nov 14 '18 at 11:19
answered Nov 13 '18 at 22:00
SocowiSocowi
6,8072725
6,8072725
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
add a comment |
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
Hi @Socowi I appreciate your response. This solves my problem. Thank you.
– Jerry M.
Nov 13 '18 at 22:27
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
If I wanted to just get the numbers, and not the space and 's', might you have advice on how to edit the given regex to match that condition (this is more for my personal learning)
– Jerry M.
Nov 13 '18 at 22:28
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
@JerryM. Glad I could help. I edited the answer such that only the numbers are extracted.
– Socowi
Nov 14 '18 at 11:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53290049%2fbash-add-regex-values-to-an-array%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 [[$line =~ [dws]; then
should be:if [[ $line =~ [a-zA-Z0-9_s] ]]; then
– anubhava
Nov 13 '18 at 21:54
Hi @anubhava, thank you for the answer. I think you noticed I did miss my closing brackets, but that regular expression returns every line, not just the values enclosed within the brackets.
– Jerry M.
Nov 13 '18 at 21:57
Yes I knew that regex is wrong but it is equivalent of what you used
[dws]
. I need more details from you about regex to suggest you the correct one.– anubhava
Nov 13 '18 at 22:00
Is
sed -En '/[[0-9]+ s]/ s/^.*[([0-9]+ s)].*/1/; p; ' log
useful, or do you need it to be a bash script?– Paul Hodges
Nov 13 '18 at 22:00
Please read the description of tags before applying them. The "linux" tag was wrong here.
– Ulrich Eckhardt
Nov 13 '18 at 22:05