Skip to content
Advertisement

grep all .js urls from text file

There is a File a.txt

https://site.tld/anythingjs.html
https://site.tld/b.txt
https://site.tld/a.js
https://site.tld/b.js?query=1
http://site.tld/c.js
http://site.tld/d.js

I want to grep all .js extension URLs so I tried this but it not showing https://site.tld/b.js?query=1

$ cat a.txt | grep '.js$'

https://site.tld/a.js
http://site.tld/c.js
http://site.tld/d.js

And when I tried this, It also select js name from anywhere

$ cat a.txt | grep '.js$*'

https://site.tld/anythingjs.html
https://site.tld/a.js
https://site.tld/b.js?query=1
http://site.tld/c.js
http://site.tld/d.js

Thanks in advance

Advertisement

Answer

Just escape the . with a

$ cat a.txt
https://site.tld/anythingjs.html
https://site.tld/b.txt
https://site.tld/a.js
https://site.tld/b.js?query=1
http://site.tld/c.js
http://site.tld/d.js

$ grep '.js' a.txt
https://site.tld/a.js
https://site.tld/b.js?query=1
http://site.tld/c.js
http://site.tld/d.js
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement