What does below Sed Command Does? [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 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

Related

Replace whole string in Vim [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
I have a .c file where I want to replace all occurrences of /*abc*/ with xyz. How do I do that in Vim?
Vim allows you to use other characters than / when substituting, so e.g. :%s#/abc/#xyz#g makes it easier when you have / as part of the pattern you're looking for.
If you want replace "/*abc*/" with "xyz", go to command mode and:
:%s/\/\*abc\*\//xyz/g
Note that "/" and "*" must be escaped.

How to mask query param values 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 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

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.

How to traverse when using `cat` command? [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 6 years ago.
Improve this question
How to travel in the shell using cat command? (arrow keys are not working)
cat > myfile
I think you are asking for a pager. For that you can use more or less (yes, these are the real names). As an example, you can use cat FILE | less or just less FILE. In there, you can scroll/search/... (exit with q).

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

Resources