$ grep --help | less
- Pipes the help output to theless
, which paginates whatever is passed into it so the console isn't spewing tons of text all at once.$ grep console.log js/app.js tests/*
- From the help output, I learned that you can search in multiple files at once by listing them after the search string. Sam also explained how the*
special character actually expands to all the files in the given scope and passes their paths into the program.- I didn't believe him, so I wrote a quick ruby program:
p ARGV
(that's the whole program--I love ruby!) and ran$ args.rb *
Sure enough, this outputted['args.rb', 'arr.rb', ...]
(also, 'args.rb' is included because it's a file in the scope of*
and not because the run command wasruby args.rb ...
) - The problem with the grep command I used was that it didn't tell me the line numbers for the console.log matches. I looked through the help some more, and eventually ran
$ grep console.log js/app.js tests/* -n
.
This outputted a nice list:js/app.js:164: console.log(bookPath); js/app.js:176: console.log('wrote: ' + this.result); js/app.js:334: console.log("error loading json from url " + url); js/app.js:335: console.log(e); js/app.js:338: console.log("timeout loading json from url " + url); js/app.js:339: console.log(e);
and I was able to identify the line I wanted gone. - So today I learned: bash and grep are pretty neat!
Friday, May 1, 2015
5/1/15 - Bash *
Today, I was trying to figure out where a console.log debug statement that I no longer needed was coming from. I asked Sam for a bit of help with grep and ended up learning a ton of interesting stuff about bash in the process. Here are the commands I did:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment