user3884301
user3884301

Reputation:

understanding sed lines in csh script

I "inherited" an old csh script, which runs fine, but now i was asked to improve something. Now I try to understand what was programmed some years ago...

At some places sed was used to extract filenames or directory names and I am not able to understand in detal what happens there. Perhaps someome is able and kind to explain it to me.

The code lines are:

set File = `echo $Dirnames[$i] |sed 's/.*\///'`".bdf"
set Dir = `echo $Dirnames[$i] | sed 's/\(.*\)\/.*/\1/'`

I understand all the code except the sed parts...

Upvotes: 0

Views: 3220

Answers (1)

SLePort
SLePort

Reputation: 15461

Assuming that Dirname[$i] is assigned a file path:

  • sed 's/.*\///': removes from path any characters up to last slash .*\/. The remaining part of the path (ie the file) is echoed with .bdf extension
  • s/\(.*\)\/.*/\1/: outputs the path of the file directory. All characters up to last / are captured \(.*\) and output using backreference \1

Upvotes: 1

Related Questions