How to delete text from variable after matching some pattern?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I wish to delete some text before some pattern. For example:
VAR="This is a test script text and real script text."
PATTERN="test "
And the desired output that I want is:
NEW_VAR="script text and real script text."
Please kindly advise me as I am new to Linux scripting.
shell-script string
add a comment |Â
up vote
0
down vote
favorite
I wish to delete some text before some pattern. For example:
VAR="This is a test script text and real script text."
PATTERN="test "
And the desired output that I want is:
NEW_VAR="script text and real script text."
Please kindly advise me as I am new to Linux scripting.
shell-script string
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wish to delete some text before some pattern. For example:
VAR="This is a test script text and real script text."
PATTERN="test "
And the desired output that I want is:
NEW_VAR="script text and real script text."
Please kindly advise me as I am new to Linux scripting.
shell-script string
I wish to delete some text before some pattern. For example:
VAR="This is a test script text and real script text."
PATTERN="test "
And the desired output that I want is:
NEW_VAR="script text and real script text."
Please kindly advise me as I am new to Linux scripting.
shell-script string
shell-script string
edited 1 min ago
Vlastimil
6,9251151124
6,9251151124
asked 5 mins ago
JefferyLR
93
93
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
If you are using a shell that supports parameter expansions of type $WORD##*STR
, then all you need to do is below.
printf '%sn' "$VAR##*$PATTERN"
To store it in the new variable, use the command substitution trick with $(..)
or use printf
's inherent capability to store the formatted string in a new variable
printf -v NEW_VAR '%s' "$VAR##*$PATTERN"
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
If you are using a shell that supports parameter expansions of type $WORD##*STR
, then all you need to do is below.
printf '%sn' "$VAR##*$PATTERN"
To store it in the new variable, use the command substitution trick with $(..)
or use printf
's inherent capability to store the formatted string in a new variable
printf -v NEW_VAR '%s' "$VAR##*$PATTERN"
add a comment |Â
up vote
0
down vote
If you are using a shell that supports parameter expansions of type $WORD##*STR
, then all you need to do is below.
printf '%sn' "$VAR##*$PATTERN"
To store it in the new variable, use the command substitution trick with $(..)
or use printf
's inherent capability to store the formatted string in a new variable
printf -v NEW_VAR '%s' "$VAR##*$PATTERN"
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you are using a shell that supports parameter expansions of type $WORD##*STR
, then all you need to do is below.
printf '%sn' "$VAR##*$PATTERN"
To store it in the new variable, use the command substitution trick with $(..)
or use printf
's inherent capability to store the formatted string in a new variable
printf -v NEW_VAR '%s' "$VAR##*$PATTERN"
If you are using a shell that supports parameter expansions of type $WORD##*STR
, then all you need to do is below.
printf '%sn' "$VAR##*$PATTERN"
To store it in the new variable, use the command substitution trick with $(..)
or use printf
's inherent capability to store the formatted string in a new variable
printf -v NEW_VAR '%s' "$VAR##*$PATTERN"
answered 3 mins ago
Inian
2,945822
2,945822
add a comment |Â
add a comment |Â
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%2f476184%2fhow-to-delete-text-from-variable-after-matching-some-pattern%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