Stop piping grep to awk, just use nawk
Say I want to generate a list of modified files in my current git repo without all the extra gubbins that git outputs.
git status | grep 'modified'
outputs:
# modified: Entity/Profile/Achievement.php
# modified: Entity/Profile/Activity.php
# modified: Entity/Profile/Category.php
or:
git status | grep 'modified' | awk '{ print $3 }'
outputs:
Entity/Profile/Achievement.php
Entity/Profile/Activity.php
Entity/Profile/Category.php
The above output is much nicer, but there's an even shorter way of achieving the same thing using nawk
because this command can do the work of grep
and awk
in one go!
git status | nawk '/modified/ { print $3 }'
outputs:
Entity/Profile/Achievement.php
Entity/Profile/Activity.php
Entity/Profile/Category.php
Pretty basic example but now I have one less command to try and remember the syntax of :)
Written by Steffan Harries
Related protips
1 Response
Do not use git status
without --porcelain
flag in your scripts. My version using "normal" AWK
git status --porcelain | awk '/^ M/ { print $2 }'
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Grep
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#