Hello All,
I am running a command
find . -name amp.cfg | cut -c 3-
which gives me output something like below
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.
rel/prod
rel/fld
deb/detail
deb/err
.
I tried tr command
tr -d 'amp.cfg'
but had no luck.
Regards,
Anand Shah
pamu
December 11, 2012, 12:40am
2
sed 's/\/amp.cfg$//' file
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
sed `s/\/\amp.cfg$//`
pamu
December 11, 2012, 12:56am
4
anand.shah:
sed `s/\/\amp.cfg$//`
"`" won't work here....
try
find . -name amp.cfg | cut -c 3- | sed 's/\/amp.cfg$//'
1 Like
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 ?
kalpeer
December 11, 2012, 6:39am
6
"$" denote for the end of the line
Below command is also another way to match your pattern
pamu
December 11, 2012, 7:00am
7
$ is used for a line which ends with amp.cfg.
Without using $ it will replace first entry of the line
Please check..
$ cat file
rel/prod/amp.cfg
rel/fld/amp.cfg
rel/fld/amp.cfg/sdd
rel/fld/amp.cfg/doc/cam/amp.cfg
$ sed 's/\/amp.cfg$//' file
rel/prod
rel/fld
rel/fld/amp.cfg/sdd
rel/fld/amp.cfg/doc/cam
$ sed 's/\/amp.cfg//' file
rel/prod
rel/fld
rel/fld/sdd
rel/fld/doc/cam/amp.cfg
Hi,
You may also try
find . -name amp.cfg | cut -c 3- | sed 's/\/amp.cfg$//'