2016-11-10 3 views
0

Что я хочу - это оболочка скрипта, которая выполняет итерацию по каждой строке команды git status, находит файлы, которые были изменены, и для каждого пути к файлу запускает заданную команду.Linux Shell Script для фильтрации команды git status

Так быть более конкретным, Учитывая этот вывод:

On branch master 
Your branch is up-to-date with 'origin/master'. 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     renamed: ASCourses-UI-vechi/src/application/Chat.fxml -> ASCourses-UI                                 /src/main/resources/fxml/ChatController.fxml 

Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to 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 

Я хочу для каждого файла, который был изменен, и начинается с ASCourses-UI-Vechi запустить git checkout file_path

Что я получил до сих пор:

Так что в настоящее время я фильтрую и обрезаю выход и получаю следующее:

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 

Проблема я не знаю, как не подстроки из первого вхождения строки ASCourses до конца всей строки

ответ

0

Использование AWK:

[[email protected] ~]$ echo "modified: ASCourses-UI-vechi/bin/.gitignore" | awk '{print $2}' 
ASCourses-UI-vechi/bin/.gitignore 

Использование СЭД:

[[email protected] ~]$ echo "modified: ASCourses-UI-vechi/bin/.gitignore" | sed 's/modified:\s\+//' 
ASCourses-UI-vechi/bin/.gitignore 
Смежные вопросы