|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sed command to remove a word from string
Hello All, I am running a command Code:
find . -name amp.cfg | cut -c 3- which gives me output something like below Code:
rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like below. Code:
rel/prod rel/fld deb/detail deb/err . I tried tr command Code:
tr -d 'amp.cfg' but had no luck. Regards, Anand Shah |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
sed 's/\/amp.cfg$//' file |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Dear Pamu, As I told in my post, i am using piped output from previous commands as input to sed so when i run this command it gives me No such file or directory error. I also tried Code:
sed `s/\/\amp.cfg$//` |
|
#4
|
|||
|
|||
|
"`" won't work here.... try Code:
find . -name amp.cfg | cut -c 3- | sed 's/\/amp.cfg$//' |
| The Following User Says Thank You to pamu For This Useful Post: | ||
anand.shah (12-11-2012) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Dear Pamu,
Thank you.Its working fine. I was using "`" instead of "'".My mistake. Can u plz tell me the use of "$" as it is working fine without that ? Last edited by anand.shah; 12-11-2012 at 01:09 AM.. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
Below command is also another way to match your pattern Quote:
Last edited by kalpeer; 12-11-2012 at 06:48 AM.. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
Without using $ it will replace first entry of the line Please check.. Code:
$ cat file rel/prod/amp.cfg rel/fld/amp.cfg rel/fld/amp.cfg/sdd rel/fld/amp.cfg/doc/cam/amp.cfg Code:
$ sed 's/\/amp.cfg$//' file rel/prod rel/fld rel/fld/amp.cfg/sdd rel/fld/amp.cfg/doc/cam Code:
$ sed 's/\/amp.cfg//' file rel/prod rel/fld rel/fld/sdd rel/fld/doc/cam/amp.cfg |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed or awk command to replace a string pattern with another string based on position of this string | vivek d r | Shell Programming and Scripting | 10 | 06-19-2012 09:35 AM |
| Using SED to extract a word or string. | simpletech369 | Shell Programming and Scripting | 2 | 01-25-2012 11:42 AM |
| remove newline between two string with sed command in unix shellscript | jcrshankar | Shell Programming and Scripting | 4 | 02-21-2011 05:46 PM |
| awk or sed command to print specific string between word and blank space | elamurugu | Shell Programming and Scripting | 5 | 12-06-2010 09:49 AM |
| how to remove spaces in a string using sed. | radhika | Shell Programming and Scripting | 4 | 06-02-2005 03:00 PM |
|
|