Issue
Updated no longer using sed
I am trying to write a script that will process certain files types that have changed in a git branch. For instance, if someone changes a file with the ".text" extension, I want to pass that file name to some sort of bash script. I also need to remove part of the file name before passing it to the bash script.
I know that if I do the following command I can get the list of git files that have changed in a branch
git diff --name-only master
Combining that with grep, I can only retrieve the files with the special extension
git diff --name-only master | grep .text
Now here is the part I cannot get to work with command line, I want to to pass in each file individually to my bash script. The below only executes echo once with all the arguments. Is this possible?
git diff --name-only master | grep .text | awk -F"folder-name/" '{print $2} | xargs -t echo
Solution
You've asked sed not to print anything by default, and you don't print anything explicitly. Here's man sed
:
-n, --quiet, --silent
suppress automatic printing of pattern space
If you want automatic printing of lines, remove -n
.
Update:
Your awk attempt is missing a single quote:
awk -F"folder-name/" '{print $2}
^-- Here
If you want to call your script with only a single argument each time, you can use xargs -n 1
. Here's man xargs
:
-n max-args, --max-args=max-args
Use at most max-args arguments per command line. Fewer than
max-args arguments will be used if the size (see the -s option)
is exceeded, unless the -x option is given, in which case xargs
will exit.
Answered By - that other guy