Deleting part of a string enclosed in brackets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting part of a string enclosed in brackets
# 8  
Old 07-29-2009
Thanks, just one problem. Now it returns an output like this:

Code:
/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
# 9  
Old 07-29-2009
Quote:
Originally Posted by pcwiz
...
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.
Here's one way to do it in Perl:

Code:
$
$ 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
# 10  
Old 07-30-2009
Quote:
Originally Posted by edidataguy
sed '1d; /@executable_path/d; s/\(^[^ ]*\) .*$/\1/; s/\(^[^ ]*\) .*$/\1/; s/\/Versions//' filename
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.
Code:
sed '1d; /@executable_path/d; s/\(^[^ ]*\) .*$/\1/; s/\/Versions.*$//' filename


Last edited by edidataguy; 07-30-2009 at 05:21 PM..
# 11  
Old 07-30-2009
Code:
 
sed -e '1d' -e '/@executable_path/d' -e 's/(.*)$//' -e  's/\/Versions.*$//' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

2. Shell Programming and Scripting

How to delete a columns of a CSV file which has cell values with a string enclosed in " , "?

Hi How can I delete a columns from a CSV file which has comma separated value with a string enclosed in double quotes or square bracket and a comma in between? I have a csv file with below format. Template,Target Server,Target Component,Rule Group,Rule,Rule Reference Number,Rule... (7 Replies)
Discussion started by: Litu19
7 Replies

3. Shell Programming and Scripting

How to delete the commas in a .CSV file that are enclosed in a string with double quotes?

Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote. Please see the sample file as below: column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Discussion started by: dhruuv369
8 Replies

4. Shell Programming and Scripting

How to delete a column/columns of a CSV file which has cell values with a string enclosed in " , "?

How can I delete a column from a CSV file which has comma separated value with a string enclosed in double quotes and a comma in between? I have a file 44.csv with 4 lines including the header like the below format: column1, column2, column3, column 4, column5, column6 12,455,"string with... (6 Replies)
Discussion started by: dhruuv369
6 Replies

5. Homework & Coursework Questions

Sed, matching nested brackets and deleting

1. The problem statement, all variables and given/known data: I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested. The input-file is: aaa { bbb ccc { ddd eee } fff { ... (2 Replies)
Discussion started by: FuzzyGnome
2 Replies

6. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

7. UNIX for Dummies Questions & Answers

Deleting part of file names

My server got messed up and the names of my files were not completely processed. As results I ended up getting a bunch of files with the following names: I need to remove the underscore and everything before it. Thus, the files will be renamed to something like this: Any help will be greatly... (3 Replies)
Discussion started by: Xterra
3 Replies

8. UNIX for Advanced & Expert Users

grep string containing [] brackets

Hello, I am trying to grep string with square brackets. for example I want to grep the below string in log.txt file. This is a test thanks in advance. (2 Replies)
Discussion started by: sureshcisco
2 Replies

9. Shell Programming and Scripting

How to substitute brackets in the beginning of string in perl?

Hi, I have a string like this user can specify different query sets that is why "or" is mentioned: $string="]("; or $string="](("; or $string="]((("; or $string="]((((("; (1 Reply)
Discussion started by: vanitham
1 Replies

10. Shell Programming and Scripting

substitution of string in brackets

Hi friends! I have a tab delimited file with two columns : GB_45_DRB SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRD SP:475928(mgmdksi rikgkg)|SP:587959(roykgl tiic-tm)|SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to... (4 Replies)
Discussion started by: jacks
4 Replies
Login or Register to Ask a Question