sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All,
I have something like below

LDC100/rel/prod/libinactrl.a
LAA2000/rel/prod/libinactrl.a
              I want to remove till first forward slash that is outputshould be as below
rel/prod/libinactrl.a
rel/prod/libinactrl.a
               How can I do that ???
sed 's:[^/]*/::' file

If these are (shell-)variable contents you best use shell variable expansion:

$ x="LDC100/rel/prod/libinactrl.a"
$ echo ${#*/}
rel/prod/libinactrl.a

Otherwise, if the values in question are in a text file, do as elixir_sinari said.

I hope this helps.

bakunin

Dear Elixir,
Your solution is not working for me.I am getting string as it is.One thing I want to clear is that, input to your command will not be any file, It will piped output of another sed command.

Please post what command you typed in.
And, if you need to adapt the solution to read from standard output of another command, simply place the command after the required pipe (after dropping the filename).

Dear Elixir,
I tried in the same way.But it didn't work.Another thing that I suspect is original strings that I posted were like below :-

LDC100/rel/prod/libinactrl.a
LAA2000/rel/prod/libinactrl.a 
         But actual strings that are coming are like below:-
LDC_100/rel/prod/libinactrl.a
LAA_2000/rel/prod/libinactrl.a 
          I suspect about special character "_"\(underscore\) that comes in string.
         Do we need to make any change in sed command to handle this ?

The sed command elixir_sinari provided would work on the strings you showed, underscore or not. The real problem is probably that you are not showing us any real data but some small sample of it. This is just stealing everybodies time.

Having said this: elixir_sinari's solution presumes the string to be changed being at the beginning of the line. This is based on the evidence you showed: the strings being at the beginning of the lines. My suspicion is that the strings are anywhere in the file, not just at the beginning of the line and therefore elixir_sinaris command won't work.

So either you present what you really see, not just an arbitrary misleading part of it, or you adapt elixir_sinaris solution to your requirements yourself.

I hope this helps.

bakunin

1 Like

I don't know what you are trying to achieve..

$ echo "LDC_100/rel/prod/libinactrl.a
LAA_2000/rel/prod/libinactrl.a" | sed 's:[^/]*/::'
rel/prod/libinactrl.a
rel/prod/libinactrl.a

@anand.shah

From now on, when you post, please provide a complete description of your problem. A complete description includes not only the error message, but the complete command or script, the data necessary to replicate your result, as well as the operating system and shell used.

This is the minimum amount of information necessary for someone to determine if their environment is suitable for reproducing your problem. Without it, you're likely wasting everyone's time.

Even if we take all of your posts in this thread and consider them as one, it still does not meet these criteria.

And, please, also be similarly specific when responding to someone with, "Your solution is not working for me." Show the command, data, errors, etc...

Regards,
Alister