How to mask query param values in Linux [closed] - linux

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Need help on below requirement.
I have a file with list of URLs and need to mask query param values as shown in below example in Linux.
http://hostname:port/uri?data=value&data1=value2&data3=value3
to
http://hostname:port/uri?data=XXX&data1=XXX&data3=XXX
thanks

you could replace any character that is not a &, it is more efficient than enumerating all possible ranges:
$ echo 'http://hostname:port/uri?data=value&data1=va%20lue2&data3=value3' | \
sed -r 's/=[^&]+/=XXX/g'
http://hostname:port/uri?data=XXX&data1=XXX&data3=XXX

Related

What does below Sed Command Does? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
I have a SED Command in a code and I need to understand what its actually doing ?
Below is what I see in code ?
show partitions {curr_table}' | sed 's/[\t]/,/g' > /tuber/dag_run_ctx/tbl_qc.csv;
Any idea what would the above Sed command do?
Replace or substitute each occurrence of <TAB> character represented as \t with , character.
And save the output into file: /tuber/dag_run_ctx/tbl_qc.csv

How to split a number in a filename in Linux? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this file name:
ABCD1B02.C50.N1995009.2019353.dat
I would like to extract the final 7 numbers and put space like this
extr=2019 353;
In bash script:
fname='ABCD1B02.C50.N1995009.2019353.dat'
extr="${fname:${#fname}-11:4} ${fname:${#fname}-7:3}"

How to cut string="Domain_12345_20180821230101.dat" into 12345_20180821 in Bash [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Provided that this sting is dynamic. If it is as Domain_1234_20180821230101.dat then I want 1234_20180821. How can I do that?
I.e., when Domain_12_20180821230101.dat then I want output as 12_20180821
A primitive solution that works for the examples you gave would be:
grep -oP '[0-9]+_[0-9]{8}' <<< "$string"
This will extract any substring consisting of a variable-length number, followed by an underscore, followed by an 8-digit number if present, else return nothing.
You can find more infos to help you understand this command and adjust it to your requirements if necessary under grep --help and https://www.regular-expressions.info/tutorial.html.

Extract IPs before string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have this text:
111.11.1.111(*)222.22.2.221(mgn)333.33.3.333(srv)
111.11.1.111(*)333.33.3.333(srv)222.22.2.222(mgn)
222.22.2.223(mgn)111.11.1.111(*)333.33.3.333(srv)
I only want to know the IP's before (mgn), output:
222.22.2.221
222.22.2.222
222.22.2.223
thanks
Through grep,
$ grep -oP '(?:\d{1,3}\.){3}\d{1,3}(?=\(mgn\))' file
222.22.2.221
222.22.2.222
222.22.2.223
Through sed,
$ sed 's/.*\b\(\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\)(mgn).*/\1/g' file
222.22.2.221
222.22.2.222
222.22.2.223

linux shell search for number that does not ocur between numbers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to search for a number in string that does not occur between numbers.
For example:
string="10003096,10007051,10003098,10007053,10000952,10002696,10003619,900004608"
If i search for 10003096, then it exists.
But if i search for 1000, then it means it does not exist.
Even if i search for 10000952,10002696, then it means it does not exist.
How can i write the shell script for this?
Please help.
I have tried various options with grep and sed but it does not help.
Pad both your 'needle' and 'haystack' with commas. E.g.
echo ",$string," | grep ",10007053,"

Resources