Extract IPs before string [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 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

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 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 automate scp for multiple server? [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 IPs of all machines are in one text file,how to do scp from one machine to all machines and automate task?
cat ips.txt | xargs -rtn1 sh -c 'scp /source-file "${1}:/target-file"' --
You probably need to adjust the command to your actual needs, which you didn't state.

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).

Resources