Search files with js declarations inside

grep -r "<script" | grep -v src | awk -F: '{print $1}' | uniq
Useful to crawl where the javascript is declared, and extract it a common file. You can redirect it to a file to review item by item.
Sample Output
path1/one.php
two.php
path2/path3/five.php

2
2014-07-23 06:24:31

What Others Think

OK, that's quite useful, but your awk is a bit unwieldy (long). Awk has field splitting built-in using -F ... | awk -F: '{print $1}' | ... Split using a colon character and print the first field. Alternatively, use cut in the same way: ... | cut -d: -f1 | ... Or for completeness, sed: ... | sed 's/:.*//' | ...
flatcap · 220 weeks and 6 days ago
Thanks @flatcap . I've modified the command with your suggestion. I usually use "cut" but now I'm trying to learn some "awk"-fu ;)
sucotronic · 220 weeks and 6 days ago
You can still simplify this a little bit with awk-fu ;) grep -r '<script' | awk -F: '!/src/{print $1}' | ...
sesom42 · 220 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: