“unterminated `s' command” when doing substitution with sed [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I'm trying to run the following sed command:



sed 's?^?'`pwd`'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt > voc.2012.test


But it is responding with an error message:



sed: -e expression #1, char 37: unterminated `s' command


What is the cause of this error and what can I do to correct it?










share|improve this question















closed as unclear what you're asking by RalfFriedl, GAD3R, Thomas, αғsнιη, Michael Homer Mar 10 at 19:51


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 3





    Does the output of pwd contain a space?

    – Kusalananda
    Mar 10 at 10:45


















-1















I'm trying to run the following sed command:



sed 's?^?'`pwd`'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt > voc.2012.test


But it is responding with an error message:



sed: -e expression #1, char 37: unterminated `s' command


What is the cause of this error and what can I do to correct it?










share|improve this question















closed as unclear what you're asking by RalfFriedl, GAD3R, Thomas, αғsнιη, Michael Homer Mar 10 at 19:51


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.













  • 3





    Does the output of pwd contain a space?

    – Kusalananda
    Mar 10 at 10:45














-1












-1








-1








I'm trying to run the following sed command:



sed 's?^?'`pwd`'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt > voc.2012.test


But it is responding with an error message:



sed: -e expression #1, char 37: unterminated `s' command


What is the cause of this error and what can I do to correct it?










share|improve this question
















I'm trying to run the following sed command:



sed 's?^?'`pwd`'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt > voc.2012.test


But it is responding with an error message:



sed: -e expression #1, char 37: unterminated `s' command


What is the cause of this error and what can I do to correct it?







text-processing sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 12:50









Kusalananda

140k17261435




140k17261435










asked Mar 10 at 10:28









user341038user341038

1




1




closed as unclear what you're asking by RalfFriedl, GAD3R, Thomas, αғsнιη, Michael Homer Mar 10 at 19:51


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by RalfFriedl, GAD3R, Thomas, αғsнιη, Michael Homer Mar 10 at 19:51


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3





    Does the output of pwd contain a space?

    – Kusalananda
    Mar 10 at 10:45













  • 3





    Does the output of pwd contain a space?

    – Kusalananda
    Mar 10 at 10:45








3




3





Does the output of pwd contain a space?

– Kusalananda
Mar 10 at 10:45






Does the output of pwd contain a space?

– Kusalananda
Mar 10 at 10:45











1 Answer
1






active

oldest

votes


















1














If the output of pwd contains a space or other whitespace character, then this would split up the sed expression into at least two parts. The first part would be an incomplete s command, and the second part would be taken as a filename.



This happens because the command substitution (the back-ticked pwd) is unquoted, i.e. it occurs outside of any single or double quote.



To remedy this, double quote the command substitution:



sed 's?^?'"$(pwd)"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


You may also choose to use the $PWD variable:



sed 's?^?'"$PWD"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


However, it looks as if you're just prepending a pathname and appending a filename suffix to every line in a file.



This could be done safer using awk:



awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt


This would work even if $PWD or the lines read from test.txt contained ?, spaces, or strings that could be interpreted as regular expressions.



Testing:



$ pwd
/tmp/shell-yash.Oeo3joN3




$ cat test.txt
hello world
sunny afternoon
bumbling bees




$ awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt
/tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/hello world.jpg
/tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/sunny afternoon.jpg
/tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/bumbling bees.jpg





share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    If the output of pwd contains a space or other whitespace character, then this would split up the sed expression into at least two parts. The first part would be an incomplete s command, and the second part would be taken as a filename.



    This happens because the command substitution (the back-ticked pwd) is unquoted, i.e. it occurs outside of any single or double quote.



    To remedy this, double quote the command substitution:



    sed 's?^?'"$(pwd)"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


    You may also choose to use the $PWD variable:



    sed 's?^?'"$PWD"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


    However, it looks as if you're just prepending a pathname and appending a filename suffix to every line in a file.



    This could be done safer using awk:



    awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt


    This would work even if $PWD or the lines read from test.txt contained ?, spaces, or strings that could be interpreted as regular expressions.



    Testing:



    $ pwd
    /tmp/shell-yash.Oeo3joN3




    $ cat test.txt
    hello world
    sunny afternoon
    bumbling bees




    $ awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt
    /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/hello world.jpg
    /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/sunny afternoon.jpg
    /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/bumbling bees.jpg





    share|improve this answer





























      1














      If the output of pwd contains a space or other whitespace character, then this would split up the sed expression into at least two parts. The first part would be an incomplete s command, and the second part would be taken as a filename.



      This happens because the command substitution (the back-ticked pwd) is unquoted, i.e. it occurs outside of any single or double quote.



      To remedy this, double quote the command substitution:



      sed 's?^?'"$(pwd)"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


      You may also choose to use the $PWD variable:



      sed 's?^?'"$PWD"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


      However, it looks as if you're just prepending a pathname and appending a filename suffix to every line in a file.



      This could be done safer using awk:



      awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt


      This would work even if $PWD or the lines read from test.txt contained ?, spaces, or strings that could be interpreted as regular expressions.



      Testing:



      $ pwd
      /tmp/shell-yash.Oeo3joN3




      $ cat test.txt
      hello world
      sunny afternoon
      bumbling bees




      $ awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt
      /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/hello world.jpg
      /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/sunny afternoon.jpg
      /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/bumbling bees.jpg





      share|improve this answer



























        1












        1








        1







        If the output of pwd contains a space or other whitespace character, then this would split up the sed expression into at least two parts. The first part would be an incomplete s command, and the second part would be taken as a filename.



        This happens because the command substitution (the back-ticked pwd) is unquoted, i.e. it occurs outside of any single or double quote.



        To remedy this, double quote the command substitution:



        sed 's?^?'"$(pwd)"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


        You may also choose to use the $PWD variable:



        sed 's?^?'"$PWD"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


        However, it looks as if you're just prepending a pathname and appending a filename suffix to every line in a file.



        This could be done safer using awk:



        awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt


        This would work even if $PWD or the lines read from test.txt contained ?, spaces, or strings that could be interpreted as regular expressions.



        Testing:



        $ pwd
        /tmp/shell-yash.Oeo3joN3




        $ cat test.txt
        hello world
        sunny afternoon
        bumbling bees




        $ awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/hello world.jpg
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/sunny afternoon.jpg
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/bumbling bees.jpg





        share|improve this answer















        If the output of pwd contains a space or other whitespace character, then this would split up the sed expression into at least two parts. The first part would be an incomplete s command, and the second part would be taken as a filename.



        This happens because the command substitution (the back-ticked pwd) is unquoted, i.e. it occurs outside of any single or double quote.



        To remedy this, double quote the command substitution:



        sed 's?^?'"$(pwd)"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


        You may also choose to use the $PWD variable:



        sed 's?^?'"$PWD"'/VOCdevkit/VOC2012/JPEGImages/?; s?$?.jpg?' test.txt


        However, it looks as if you're just prepending a pathname and appending a filename suffix to every line in a file.



        This could be done safer using awk:



        awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt


        This would work even if $PWD or the lines read from test.txt contained ?, spaces, or strings that could be interpreted as regular expressions.



        Testing:



        $ pwd
        /tmp/shell-yash.Oeo3joN3




        $ cat test.txt
        hello world
        sunny afternoon
        bumbling bees




        $ awk ' printf("%s/VOCdevkit/VOC2012/JPEGImages/%s.jpgn", ENVIRON["PWD"], $0) ' test.txt
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/hello world.jpg
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/sunny afternoon.jpg
        /tmp/shell-yash.Oeo3joN3/VOCdevkit/VOC2012/JPEGImages/bumbling bees.jpg






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 10 at 11:46

























        answered Mar 10 at 11:16









        KusalanandaKusalananda

        140k17261435




        140k17261435












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?