Linux Shell Script to filter git status command -
what want script shell iterates through each line of git status
command, finds files modified , each file path run given command.
so more specific, given output:
on branch master branch up-to-date 'origin/master'. changes committed: (use "git reset head <file>..." unstage) renamed: ascourses-ui-vechi/src/application/chat.fxml -> ascourses-ui /src/main/resources/fxml/chatcontroller.fxml changes not staged commit: (use "git add <file>..." update committed) (use "git checkout -- <file>..." discard changes in working directory) modified: ascourses-ui-vechi/bin/.gitignore modified: ascourses-ui-vechi/bin/application/chat.css modified: ascourses-ui-vechi/bin/application/chat.fxml modified: ascourses-ui-vechi/bin/application/chatcontroller$1.class modified: ascourses-ui-vechi/bin/application/chatcontroller$2.class modified: ascourses-ui-vechi/bin/application/chatcontroller$3$1.class modified: ascourses-ui-vechi/bin/application/chatcontroller$3.class modified: ascourses-ui-vechi/bin/application/chatcontroller$4.class modified: ascourses-ui-vechi/bin/application/chatcontroller$5.class
i want each file modified , starts ascourses-ui-vechi run git checkout file_path
what got far this:
#!/bin/bash (ifs=' ' x in ` git status | grep -e 'modified.*ascourses-ui-vechi' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'`; echo $x; done)
so filter , trim output , this:
modified: ascourses-ui-vechi/bin/.gitignore modified: ascourses-ui-vechi/bin/application/chat.css modified: ascourses-ui-vechi/bin/application/chat.fxml modified: ascourses-ui-vechi/bin/application/chatcontroller$1.class modified: ascourses-ui-vechi/bin/application/chatcontroller$2.class modified: ascourses-ui-vechi/bin/application/chatcontroller$3$1.class modified: ascourses-ui-vechi/bin/application/chatcontroller$3.class modified: ascourses-ui-vechi/bin/application/chatcontroller$4.class modified: ascourses-ui-vechi/bin/application/chatcontroller$5.class
problem don't know how substring first occurrence of ascourses string until end of whole string
using awk:
[user@user ~]$ echo "modified: ascourses-ui-vechi/bin/.gitignore" | awk '{print $2}' ascourses-ui-vechi/bin/.gitignore
using sed:
[user@user ~]$ echo "modified: ascourses-ui-vechi/bin/.gitignore" | sed 's/modified:\s\+//' ascourses-ui-vechi/bin/.gitignore
Comments
Post a Comment