简体   繁体   中英

Manipulating strings in bash

I have a file that contains a page of google which I got after a search. I used

w3m -no-cookie $search > google

to make the page

after that I need to get all the sites contained in that page, so basically all the strings that start with "www" and end with "/"

I tried :

grep -Fw "www" google | awk -F "/" '{ print $1";" }'

but it gives me everything that is on the line before www

how do I remove that?

should I use sed?

thanks!

Assuming that all sites start with www is a bit weird, but here it is:

Your problem is that grep will return the whole line. With -o it will only return the matched part:

grep -wo "www.*" google | awk -F "/" '{ print $1";" }'

or simply:

grep -wo "www[^/]*" google

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