'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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | NNK |
