Filter last word after matching a string
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am writing a bash script and I need to filter out some hexadecimal value from a return string of a command in bash for example:
hexVal=`mmc extcsd read /dev/mmcblk1 | grep 'Max Enhanced Area Size'`
Will return the value of hexVal as:
Max Enhanced Are Size [MAX_ENH_SIZE_MULT]: 0x000bd8
Now, I need the value of hexVal to be returned as:
0x000bd8
text-processing grep
New contributor
add a comment |Â
up vote
0
down vote
favorite
I am writing a bash script and I need to filter out some hexadecimal value from a return string of a command in bash for example:
hexVal=`mmc extcsd read /dev/mmcblk1 | grep 'Max Enhanced Area Size'`
Will return the value of hexVal as:
Max Enhanced Are Size [MAX_ENH_SIZE_MULT]: 0x000bd8
Now, I need the value of hexVal to be returned as:
0x000bd8
text-processing grep
New contributor
Are those values always last words in the line?
â jimmij
10 mins ago
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am writing a bash script and I need to filter out some hexadecimal value from a return string of a command in bash for example:
hexVal=`mmc extcsd read /dev/mmcblk1 | grep 'Max Enhanced Area Size'`
Will return the value of hexVal as:
Max Enhanced Are Size [MAX_ENH_SIZE_MULT]: 0x000bd8
Now, I need the value of hexVal to be returned as:
0x000bd8
text-processing grep
New contributor
I am writing a bash script and I need to filter out some hexadecimal value from a return string of a command in bash for example:
hexVal=`mmc extcsd read /dev/mmcblk1 | grep 'Max Enhanced Area Size'`
Will return the value of hexVal as:
Max Enhanced Are Size [MAX_ENH_SIZE_MULT]: 0x000bd8
Now, I need the value of hexVal to be returned as:
0x000bd8
text-processing grep
text-processing grep
New contributor
New contributor
edited 4 mins ago
Inian
3,233822
3,233822
New contributor
asked 14 mins ago
Hari
1
1
New contributor
New contributor
Are those values always last words in the line?
â jimmij
10 mins ago
add a comment |Â
Are those values always last words in the line?
â jimmij
10 mins ago
Are those values always last words in the line?
â jimmij
10 mins ago
Are those values always last words in the line?
â jimmij
10 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
Instead of grep
, you could use awk
as it is more useful in pattern matching and printing out the matched fields
mmc extcsd read /dev/mmcblk1 | awk -F: '$1 ~ "^""Max Enhanced Area Size" print $2 '
You could also remove the leading space in the above result
awk -F: '$1 ~ "^""Max Enhanced Area Size" sub(/^[[:space:]]/,"",$2); print $2 '
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Instead of grep
, you could use awk
as it is more useful in pattern matching and printing out the matched fields
mmc extcsd read /dev/mmcblk1 | awk -F: '$1 ~ "^""Max Enhanced Area Size" print $2 '
You could also remove the leading space in the above result
awk -F: '$1 ~ "^""Max Enhanced Area Size" sub(/^[[:space:]]/,"",$2); print $2 '
add a comment |Â
up vote
0
down vote
Instead of grep
, you could use awk
as it is more useful in pattern matching and printing out the matched fields
mmc extcsd read /dev/mmcblk1 | awk -F: '$1 ~ "^""Max Enhanced Area Size" print $2 '
You could also remove the leading space in the above result
awk -F: '$1 ~ "^""Max Enhanced Area Size" sub(/^[[:space:]]/,"",$2); print $2 '
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Instead of grep
, you could use awk
as it is more useful in pattern matching and printing out the matched fields
mmc extcsd read /dev/mmcblk1 | awk -F: '$1 ~ "^""Max Enhanced Area Size" print $2 '
You could also remove the leading space in the above result
awk -F: '$1 ~ "^""Max Enhanced Area Size" sub(/^[[:space:]]/,"",$2); print $2 '
Instead of grep
, you could use awk
as it is more useful in pattern matching and printing out the matched fields
mmc extcsd read /dev/mmcblk1 | awk -F: '$1 ~ "^""Max Enhanced Area Size" print $2 '
You could also remove the leading space in the above result
awk -F: '$1 ~ "^""Max Enhanced Area Size" sub(/^[[:space:]]/,"",$2); print $2 '
answered 7 mins ago
Inian
3,233822
3,233822
add a comment |Â
add a comment |Â
Hari is a new contributor. Be nice, and check out our Code of Conduct.
Hari is a new contributor. Be nice, and check out our Code of Conduct.
Hari is a new contributor. Be nice, and check out our Code of Conduct.
Hari is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479292%2ffilter-last-word-after-matching-a-string%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Are those values always last words in the line?
â jimmij
10 mins ago