grep nth position in a string and echo it [on hold]
Clash Royale CLAN TAG#URR8PPP
up vote
-5
down vote
favorite
I have this string below:
out[000: ]<ISO9090-9999999902299>
I want to grep "022" in using a script and echo it out.
linux grep
New contributor
put on hold as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, JigglyNaga, thrig, Archemar yesterday
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-5
down vote
favorite
I have this string below:
out[000: ]<ISO9090-9999999902299>
I want to grep "022" in using a script and echo it out.
linux grep
New contributor
put on hold as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, JigglyNaga, thrig, Archemar yesterday
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
1
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
I have this string below:
out[000: ]<ISO9090-9999999902299>
I want to grep "022" in using a script and echo it out.
linux grep
New contributor
I have this string below:
out[000: ]<ISO9090-9999999902299>
I want to grep "022" in using a script and echo it out.
linux grep
linux grep
New contributor
New contributor
edited yesterday
Rui F Ribeiro
38.1k1475123
38.1k1475123
New contributor
asked yesterday
developer_
61
61
New contributor
New contributor
put on hold as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, JigglyNaga, thrig, Archemar yesterday
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as unclear what you're asking by Jeff Schaller, Rui F Ribeiro, JigglyNaga, thrig, Archemar yesterday
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
4
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
1
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday
add a comment |
4
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
1
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday
4
4
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
1
1
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Insist on grep
? Try
$ echo "out[000: ]<ISO9090-9999999902299>" | grep -Eo "ISO.13..." | grep -Eo "...$"
022
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable thatgrep
can't deal with immediately. If it is printed from some program / command, pipe it into thegrep
s.
– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...
– RudiC
18 hours ago
add a comment |
up vote
0
down vote
Perl:
echo "out[000: ]<ISO9090-9999999902299>" | perl -lne 'print substr($_,27,3)'
AWK:
echo "out[000: ]<ISO9090-9999999902299>" | awk 'print substr($0,28,3)'
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Insist on grep
? Try
$ echo "out[000: ]<ISO9090-9999999902299>" | grep -Eo "ISO.13..." | grep -Eo "...$"
022
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable thatgrep
can't deal with immediately. If it is printed from some program / command, pipe it into thegrep
s.
– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...
– RudiC
18 hours ago
add a comment |
up vote
0
down vote
Insist on grep
? Try
$ echo "out[000: ]<ISO9090-9999999902299>" | grep -Eo "ISO.13..." | grep -Eo "...$"
022
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable thatgrep
can't deal with immediately. If it is printed from some program / command, pipe it into thegrep
s.
– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...
– RudiC
18 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Insist on grep
? Try
$ echo "out[000: ]<ISO9090-9999999902299>" | grep -Eo "ISO.13..." | grep -Eo "...$"
022
Insist on grep
? Try
$ echo "out[000: ]<ISO9090-9999999902299>" | grep -Eo "ISO.13..." | grep -Eo "...$"
022
answered yesterday
RudiC
2,9561211
2,9561211
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable thatgrep
can't deal with immediately. If it is printed from some program / command, pipe it into thegrep
s.
– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...
– RudiC
18 hours ago
add a comment |
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable thatgrep
can't deal with immediately. If it is printed from some program / command, pipe it into thegrep
s.
– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...
– RudiC
18 hours ago
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
why should i echo the string, why not grep from it just?
– developer_
19 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable that
grep
can't deal with immediately. If it is printed from some program / command, pipe it into the grep
s.– RudiC
18 hours ago
You didn't specify how and where that string is stored / comes from. "String" usually refers to a (shell?) variable that
grep
can't deal with immediately. If it is printed from some program / command, pipe it into the grep
s.– RudiC
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
that is coming from a debug file called test.debug with that string.
– developer_
18 hours ago
grep
can read files...– RudiC
18 hours ago
grep
can read files...– RudiC
18 hours ago
add a comment |
up vote
0
down vote
Perl:
echo "out[000: ]<ISO9090-9999999902299>" | perl -lne 'print substr($_,27,3)'
AWK:
echo "out[000: ]<ISO9090-9999999902299>" | awk 'print substr($0,28,3)'
add a comment |
up vote
0
down vote
Perl:
echo "out[000: ]<ISO9090-9999999902299>" | perl -lne 'print substr($_,27,3)'
AWK:
echo "out[000: ]<ISO9090-9999999902299>" | awk 'print substr($0,28,3)'
add a comment |
up vote
0
down vote
up vote
0
down vote
Perl:
echo "out[000: ]<ISO9090-9999999902299>" | perl -lne 'print substr($_,27,3)'
AWK:
echo "out[000: ]<ISO9090-9999999902299>" | awk 'print substr($0,28,3)'
Perl:
echo "out[000: ]<ISO9090-9999999902299>" | perl -lne 'print substr($_,27,3)'
AWK:
echo "out[000: ]<ISO9090-9999999902299>" | awk 'print substr($0,28,3)'
answered yesterday
simlev
6032214
6032214
add a comment |
add a comment |
4
What's important about 022? With that string , you could just echo 022 and be done. Is it 7+3 characters from the end? Some number+3 from the beginning? Or some number after a (dash or less-than or "ISO" or dash or a string of 9's or.....?)
– Jeff Schaller
yesterday
The importance of 022 or position 17 to 19 in that iso standard are where issues are detected. that would give the error. in the example i gave 022 gives some issues to be resolved. if its grepped or sed or awk the i should echo rather than showing everything.
– developer_
yesterday
1
Then I think your question would be better described as "extract the characters in positions 17-19 from a string" and better yet it would say if the string is piped in as input or is in a variable or is entered by the user or passed as a parameter to your script.
– Jeff Schaller
yesterday