Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Manipulation with the string using sed

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-31-2013
anand.shah anand.shah is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 20 September 2014, 1:16 AM EDT
Posts: 45
Thanks: 11
Thanked 0 Times in 0 Posts
Manipulation with the string using sed

hello All,
When I run
Code:
 find

command on certain directory I may get one of the following output depending on configuration

Code:
A. ./rel/prod/libpam.a
B. ./rel/fld/libpam.a
C. ./deb/detail/libpam.a
D. ./deb/err/libpam.a

I want to get output as below

Code:
A. rel/prod
B. rel/fld
C. deb/detail
D. deb/err

respectively.
I can get rid of leading "./" characters by using cut command cut -c 3-5 but how to get rid of trailing "/libpam.a" ??

Regards,
Anand Shah
Sponsored Links
    #2  
Old Unix and Linux 01-31-2013
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 August 2016, 9:27 AM EDT
Location: Aachen, Germany
Posts: 9,249
Thanks: 181
Thanked 2,697 Times in 2,525 Posts
man find . Have you tried the option -type d ?

To get rid of unwanted chars in your output lines, sed is your friend, e.g. sed 's:^..::' to remove the two initial chars.
Sponsored Links
    #3  
Old Unix and Linux 01-31-2013
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
With awk

Code:
awk -F"[ ./]" '{print $1". "$5"/"$(NF-2)}' file
A. rel/prod
B. rel/fld
C. deb/detail
D. deb/err

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting part of a string : string manipulation vivek d r Shell Programming and Scripting 7 04-20-2012 11:12 AM
sed string manipulation in shell script mirfan Shell Programming and Scripting 12 05-19-2010 07:00 AM
I need help with string manipulation c3lica Shell Programming and Scripting 1 02-15-2009 10:05 PM
sed string manipulation speedieB Shell Programming and Scripting 4 11-23-2008 07:27 PM
How to use sed for string manipulation hikrishn Shell Programming and Scripting 2 06-16-2008 11:43 AM



All times are GMT -4. The time now is 09:30 AM.