mrlayance
mrlayance

Reputation: 663

Removing matching text from line

I have a example cut down from a log file.

112 172.172.172.1#50912 (ssl.bing.com):

I would like some how to remove the # and numbers after and (): from the url.

Would like the result.

112 172.172.172.1 ssl.bing.com

Here is the sed oneliner I have been working on.

cat newdns.log | sed -e 's/.*query: //' | cut -f 1 -d' ' | sort | uniq -c | sort -k2 > old.log

Thanks

Upvotes: 0

Views: 42

Answers (2)

jaypal singh
jaypal singh

Reputation: 77105

Another sed:

sed -r 's/#[^ ]+|[():]//g'

$ echo '112 172.172.172.1#50912 (ssl.bing.com):' | sed -r 's/#[^ ]+|[():]//g'
112 172.172.172.1 ssl.bing.com

Upvotes: 1

devnull
devnull

Reputation: 123508

Using sed, you could say:

sed 's/#[0-9]*//;s/(\(.*\)):$/\1/' filename

or, in a single substitution:

sed 's/#[0-9]* *(\(.*\)):$/ \1/' filename

Upvotes: 2

Related Questions