Manipulation with the string using sed | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Manipulation with the string using sed

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-31-2013
anand.shah anand.shah is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 22 July 2014, 5:25 AM EDT
Posts: 42
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 01-31-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 22 August 2014, 12:02 PM EDT
Location: Aachen, Germany
Posts: 4,093
Thanks: 67
Thanked 972 Times in 922 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 01-31-2013
Jotne's Avatar
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 22 August 2014, 7:56 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:20 AM.