1

I have a file like this:

ins.pro.server.pro.net ins.pro-server2.pro.net ins.pro-server3.pro.net ins.pro-server4.pro.net 

I would like to cat this file but eliminating the specific string ".pro.net" from all the lines, so it can result like this:

ins.pro-server ins.pro-server2 ins.pro-server3 ins.pro-server4 

Thank you in advance for your help

P.S.: I have used some sed options before but it also deleted the first part from "ins.pro-server" leaving it like "ins.-server"

2 Answers 2

-2

I'm doing this from memory, but I believe the following should work:

cat $file | sed s/\.pro\.net//

Reference: Sed Tutorial by Bruce Barnett

MVP (below) is correct. For some reason, my backslashes on the dots didn't come through (I guess I need to escape them?). Also, the cat is redundant, because you can just add the file argument at the end, the way MVP suggested.

(I'd comment on his answer, but I don't have 50 rep yet) (Backslashes in my answer were originally missing because I didn't escape them)

4

Use this:

sed "s/\.pro\.net//g" file 

First, you don't need cat for that, second, make sure to use \. instead of just ., because dot means match any symbol. It may appear to work, but it would also match string xproynet, which is probably not what you want.

3
  • Using single quotes rather than double quotes for sed commands (e.g., sed 's/\.pro\.net//g' file) is a good habit to get into. Commented Oct 11, 2014 at 1:12
  • @G-man: this is just matter of personal preference. I prefer to use double quotes for strings as this is C/C++ way. In shell both work fine Commented Oct 11, 2014 at 6:14
  • It's only a matter of personal preference until your store has a half-price sale, and you want to edit your price list with sed "s/$2/$1/g". My point is that sed commands often have things in them that get interpreted by the shell if they are in double quotes. Commented Oct 13, 2014 at 20:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.