Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use shell command to check SVN check-out files and create links in an directory

Tags:

bash

svn

Basically my question is how to use bash shell command to do following automatically, so I can track modified files easily.

  1. list svn check-out files
  2. create link files to above files in an directory called "change"

laptop$ svn status -q

M            rcms/src/config/ta_show.c
M            rcms/src/config/ta_config.c

laptop$ cd  change
laptop$ link -s ../rcms/src/config/ta_show.c ta_show.c
laptop$ link -s ../rcms/src/config/ta_config.c ta_config.c

laptop$ ls
lrwxrwxrwx 1 root root 59 Nov 27 12:24 ta_show.c -> ../rcms/src/config/ta_show.c
lrwxrwxrwx 1 root root 59 Nov 27 12:24 ta_config.c -> ../rcms/src/config/ta_config.c

I am thinking to use shell command like below:

$ svn status -q | sed 's/M       //' | xargs -I xxx ln -s ***BETWEEN REAL FILE AND BASE FILENAME***
like image 431
Yan X Avatar asked Dec 02 '25 15:12

Yan X


1 Answers

you have two things need to be concerned:

  • the empty line between each file with svn status 'M'
  • extract the file name

the awk one liner could do it:

awk '$0{x=$2;gsub(".*/","",x);print "ln -s ../"$2" "x}'

so if you pipe your svn status output to the line above, it print the ln -s command lines for you.

if you want the ln -s lines to get executed, you could either pipe the output to sh (svn status|awk ...|sh) or replace the print with system

at the end i would like to show the output below as an exmple:

kent$ echo "M            rcms/src/config/ta_show.c

M            rcms/src/config/ta_config.c"|awk '$0{x=$2;gsub(".*/","",x);print "ln -s .."$2" "x}'
ln -s ../rcms/src/config/ta_show.c ta_show.c
ln -s ../rcms/src/config/ta_config.c ta_config.c
like image 182
Kent Avatar answered Dec 04 '25 08:12

Kent