Deleting part of a string enclosed in brackets

I use otool on OS X to figure out the shared libraries that a binary uses. I run this command:

otool -L /Applications/Vidnik\ 0.13.0/Vidnik.app/Contents/MacOS/Vidnik

And it returns an output similar to this:

/Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:
	/usr/lib/libcrypto.0.9.7.dylib (compatibility version 0.9.7, current version 0.9.7)
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 677.15.0)
	/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 67.0.0)
	/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.5.1)
	/System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 33001.0.0)
	@executable_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle (compatibility version 1.5.0, current version 1.5.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 32.0.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.10.0)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 949.27.0)
	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 34.0.0)

What I need to do is completely delete the first line of the output (this line: /Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:) and on each following line that lists a library, I need to delete the part in brackets (e.g. something like "(compatibility version x.x.x., current version, x.x.x)"). And then I need to delete any line that begins with "@executable_path". I know this is a long one, but I hope its possible

Any help would be appreciated

Thanks

See if this works.

 
 sed -e '1d' -e '/@executable_path/d'  filename | cut -d " " -f1

That worked brilliantly, thank you very much :slight_smile:

awk can do the job alone :wink:

awk 'NR>1{print $1}' file 

A small refinement, just one sed command is enough:

sed '1d; /@executable_path/d; s/\(^[^ ]*\) .*$/\1/' filename

Thanks everyone. The above command returns an output similar to this:

/usr/lib/libcrypto.0.9.7.dylib
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit
/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore
/System/Library/Frameworks/QTKit.framework/Versions/A/QTKit
/System/Library/Frameworks/Security.framework/Versions/A/Security
/usr/lib/libgcc_s.1.dylib
/usr/lib/libSystem.B.dylib
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
/usr/lib/libobjc.A.dylib
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices

Is it possible to make one further refinement to take out the part of each path that has "/Versions" in it. For example this:

/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit

Would become this:

/System/Library/Frameworks/AppKit.framework

Basically any part of a path that starts with "/Versions" is removed.

sed '1d; /@executable_path/d; s/\(^[^ ]\) .$/\1/; s/\(^[^ ]\) .$/\1/; s/\/Versions//' filename

Thanks, just one problem. Now it returns an output like this:

/usr/lib/libcrypto.0.9.7.dylib
/System/Library/Frameworks/Cocoa.framework/A/Cocoa
/System/Library/Frameworks/Foundation.framework/C/Foundation
/System/Library/Frameworks/QuickTime.framework/A/QuickTime
/System/Library/Frameworks/OpenGL.framework/A/OpenGL
/System/Library/Frameworks/AudioUnit.framework/A/AudioUnit
/System/Library/Frameworks/QuartzCore.framework/A/QuartzCore
/System/Library/Frameworks/QTKit.framework/A/QTKit
/System/Library/Frameworks/Security.framework/A/Security

It has indeed taken out the "/Versions" part of the path, but I need it to take out everything after /Versions in each file path. In the above output, parts like "/A/Cocoa" are left (originally "/Versions/A/Cocoa")

Thanks

Here's one way to do it in Perl:

$
$ cat data.txt
/Applications/Vidnik 0.13.0/Vidnik.app/Contents/MacOS/Vidnik:
        /usr/lib/libcrypto.0.9.7.dylib (compatibility version 0.9.7, current version 0.9.7)
        /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 12.0.0)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 677.15.0)
        /System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 67.0.0)
        /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.5.1)
        /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 33001.0.0)
        @executable_path/../Frameworks/Sparkle.framework/Versions/A/Sparkle (compatibility version 1.5.0, current version 1.5.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.0.0)
        /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 32.0.0)
        /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.10.0)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 949.27.0)
        /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 34.0.0)
$
$
$ perl -ne 'if ($.>1 and /^\s+\//){s/^\s+| \(.*\)|\/Versions[\w\/]+//sg;print}' data.txt
/usr/lib/libcrypto.0.9.7.dylib
/System/Library/Frameworks/Cocoa.framework
/System/Library/Frameworks/Foundation.framework
/System/Library/Frameworks/QuickTime.framework
/System/Library/Frameworks/OpenGL.framework
/System/Library/Frameworks/AudioUnit.framework
/System/Library/Frameworks/QuartzCore.framework
/System/Library/Frameworks/QTKit.framework
/System/Library/Frameworks/Security.framework
/usr/lib/libgcc_s.1.dylib
/usr/lib/libSystem.B.dylib
/System/Library/Frameworks/CoreServices.framework
/usr/lib/libobjc.A.dylib
/System/Library/Frameworks/CoreFoundation.framework
/System/Library/Frameworks/AppKit.framework
/System/Library/Frameworks/ApplicationServices.framework
$
$

tyler_durden

1...Please first, make sure what your requirements are and then ask for help.
Check back, the command does what you requested.
2...It will be nice if you come up with all your requirements in one go.
3...Also, you should study the code and try to fix this minor change.
OK. Here is the new one.

sed '1d; /@executable_path/d; s/\(^[^ ]*\) .*$/\1/; s/\/Versions.*$//' filename

  1. ^ ↩︎

  2. ^ ↩︎

 
sed -e '1d' -e '/@executable_path/d' -e 's/(.*)$//' -e  's/\/Versions.*$//' file