Fl.pf.
Fl.pf.

Reputation: 345

Delete certain length of substring

A call of svn status gives me a list of files that are different than in the svn image.

D       subs/abc/deleted_sub.f90
M       subs/abc/modified_sub.f90
M       subs/abc/Makefile.Routinen

I need a string compile_string to gmake $compile_string.

What I do not want in my string are files declared D for deleted and Makefile.Routinen files.

I do also not want to work with temporary files (I have a working script but using temporary files is not desirable).

So I read my svn status into a string:

comp_files=$(svn status)

So I get a long string D subs/abc/deleted_sub.f90 M subs/abc/modified_sub.f90 M subs/abc/Makefile.Routinen.

How can I now delete the next filepath after a 'D' or if its a Makefile.Routinen file?

Upvotes: 0

Views: 52

Answers (2)

Sundeep
Sundeep

Reputation: 23667

awk is a good fit when working with columns

comp_files=$(svn status | awk '$1 != "D" && $2 !~ /Makefile\.Routinen/{print $2}')
  • $1 != "D" first column shouldn't match literal string D
  • $2 !~ /Makefile\.Routinen/ second column shouldn't contain the string Makefile.Routinen
  • {print $2} if both conditions satisfy, print second column


If entire line content is needed instead of second column alone,

comp_files=$(svn status | awk '$1 != "D" && $2 !~ /Makefile\.Routinen/')

Upvotes: 1

GMichael
GMichael

Reputation: 2776

Please try

comp_files=$(svn status | grep -E -v '^D|Makefile.Routinen')

Upvotes: 1

Related Questions