0

I have a set of key/value pairs that lists executables using the fully qualified name as follows:

  ["exec"] = "/share/home/00288/tg455591/NAMD_2.8b3/NAMD_2.8b3_Linux-x86_64-MVAPICH-Intel-Ranger/namd2",

However, I would like to take out the directory location and only print the executable, such as the following:

  ["exec"] = "namd2",

How can I construct a regular expression to make this change? Keep in mind all the executables in the file are different, but they have similar format. The size of the file is approximately 6000 lines. Thanks in advance.

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
amber4478
  • 6,433
  • 3
  • 20
  • 17

3 Answers3

1

This regular expression did the trick:

(?<=\["exec"\] = ").+?(?=[^/]+?(?:\.\w+)?")

Replace with:

\1\2
amber4478
  • 6,433
  • 3
  • 20
  • 17
1

try this to find :

(?<="exec"] = ")[^"]*?/([^/"]+)(?=")

and this to replace :

\1

(or $1)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
0

If I understand the problem correctly, this sed command will do the trick:

sed 's|= .*/|= "|'
Beta
  • 96,650
  • 16
  • 149
  • 150
  • sed 's|= .*/|= "\' lariatData-sgeT-2012-05-01_2.lua sed: 1: "s|= .*/|= "\": unterminated substitute in regular expression is the error I get when I try the sed command – amber4478 Apr 16 '13 at 03:09
  • @amber4478: It's `"|'`, not `"\'`. – Beta Apr 16 '13 at 03:21