简体   繁体   中英

Remove all hyperlinks in a text file, linux scripting

I am very new in scripting, but I want to learn it. What I have to do is to remove all occurrences of something like http://* from a text file. I want to do it with sed command and regular expressions.

Here is what I have come up to so far:

sed 's/http:\/\/.*/ /' < input.txt > output.txt

This code replaces all the hyperlinks with a space. But the problem is that it also removes the rest of the line.

How can I fix this problem? I have tried adding space, "http://.* " or end of word "http://.*\\>" or other tricks that I found in the internet, but they didn't work.

And is there a better way to do so instead of using sed?

Sed is a fine way to do this. Try changing your regex to s!http://[^[:space:]]*! !g s!http://[^[:space:]]*! !g .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM