Enter IP at the end of a specific line [closed]

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












0















I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip:



# gfhfhgfh
gfhfghgfhgfhgfh
MACs
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65
/bin/false


I want to add an ip in the end of the line that contains as patron USER CONSOLE:



 USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,


I only manage to add the ip in the whole document at the moment but not in that particular line the code used is



sed 's/r?$/,!10.10.11.1/' file.txt 









share|improve this question















closed as unclear what you're asking by G-Man, Mr Shunz, msp9011, andcoz, Archemar Jan 21 at 13:19


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.


















  • Please edit your question and spell the string consistently.

    – G-Man
    Jan 18 at 23:58











  • I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

    – ortiga
    Jan 19 at 9:52












  • The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

    – steeldriver
    Jan 19 at 13:43















0















I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip:



# gfhfhgfh
gfhfghgfhgfhgfh
MACs
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65
/bin/false


I want to add an ip in the end of the line that contains as patron USER CONSOLE:



 USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,


I only manage to add the ip in the whole document at the moment but not in that particular line the code used is



sed 's/r?$/,!10.10.11.1/' file.txt 









share|improve this question















closed as unclear what you're asking by G-Man, Mr Shunz, msp9011, andcoz, Archemar Jan 21 at 13:19


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.


















  • Please edit your question and spell the string consistently.

    – G-Man
    Jan 18 at 23:58











  • I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

    – ortiga
    Jan 19 at 9:52












  • The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

    – steeldriver
    Jan 19 at 13:43













0












0








0








I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip:



# gfhfhgfh
gfhfghgfhgfhgfh
MACs
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65
/bin/false


I want to add an ip in the end of the line that contains as patron USER CONSOLE:



 USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,


I only manage to add the ip in the whole document at the moment but not in that particular line the code used is



sed 's/r?$/,!10.10.11.1/' file.txt 









share|improve this question
















I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip:



# gfhfhgfh
gfhfghgfhgfhgfh
MACs
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65
/bin/false


I want to add an ip in the end of the line that contains as patron USER CONSOLE:



 USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,


I only manage to add the ip in the whole document at the moment but not in that particular line the code used is



sed 's/r?$/,!10.10.11.1/' file.txt 






linux text-processing scripting ip-address






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 2:27









Jeff Schaller

40.9k1056130




40.9k1056130










asked Jan 18 at 23:15









ortigaortiga

83




83




closed as unclear what you're asking by G-Man, Mr Shunz, msp9011, andcoz, Archemar Jan 21 at 13:19


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 G-Man, Mr Shunz, msp9011, andcoz, Archemar Jan 21 at 13:19


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.














  • Please edit your question and spell the string consistently.

    – G-Man
    Jan 18 at 23:58











  • I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

    – ortiga
    Jan 19 at 9:52












  • The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

    – steeldriver
    Jan 19 at 13:43

















  • Please edit your question and spell the string consistently.

    – G-Man
    Jan 18 at 23:58











  • I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

    – ortiga
    Jan 19 at 9:52












  • The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

    – steeldriver
    Jan 19 at 13:43
















Please edit your question and spell the string consistently.

– G-Man
Jan 18 at 23:58





Please edit your question and spell the string consistently.

– G-Man
Jan 18 at 23:58













I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

– ortiga
Jan 19 at 9:52






I'm using this command that really does what I want: sed -i /USER CONSOLA/s/r/-------/' file.txt but now inside the text I see all the lines at the end with ^ M

– ortiga
Jan 19 at 9:52














The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

– steeldriver
Jan 19 at 13:43





The ^M sequence likely indicates that your file has Windows line endings - you can remove them with dos2unix or see for example How to remove Ctrl-M from files where dos2unix, perl, tr, and sed are not present?

– steeldriver
Jan 19 at 13:43










2 Answers
2






active

oldest

votes


















2














Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor):



$ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
# gfhfhgfh
gfhfghgfhgfhgfh
MACs
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1
/bin/false



If your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to



sed '/^USER CONSOLA/ s/r$/,!10.10.11.1r/' file.txt


If you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed:



sed -e 's/r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt





share|improve this answer
































    -1














    Used below method to achieve same



    sed "/USER CONSOLA/s/.*/&,!10.249.245.90,/g" filename


    output



    # gfhfhgfh
    gfhfghgfhgfhgfh
    MACs
    # access
    USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.249.245.90,
    /bin/false





    share|improve this answer





























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor):



      $ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
      # gfhfhgfh
      gfhfghgfhgfhgfh
      MACs
      # access
      USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1
      /bin/false



      If your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to



      sed '/^USER CONSOLA/ s/r$/,!10.10.11.1r/' file.txt


      If you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed:



      sed -e 's/r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt





      share|improve this answer





























        2














        Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor):



        $ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
        # gfhfhgfh
        gfhfghgfhgfhgfh
        MACs
        # access
        USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1
        /bin/false



        If your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to



        sed '/^USER CONSOLA/ s/r$/,!10.10.11.1r/' file.txt


        If you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed:



        sed -e 's/r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt





        share|improve this answer



























          2












          2








          2







          Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor):



          $ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
          # gfhfhgfh
          gfhfghgfhgfhgfh
          MACs
          # access
          USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1
          /bin/false



          If your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to



          sed '/^USER CONSOLA/ s/r$/,!10.10.11.1r/' file.txt


          If you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed:



          sed -e 's/r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt





          share|improve this answer















          Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor):



          $ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
          # gfhfhgfh
          gfhfghgfhgfhgfh
          MACs
          # access
          USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1
          /bin/false



          If your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to



          sed '/^USER CONSOLA/ s/r$/,!10.10.11.1r/' file.txt


          If you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed:



          sed -e 's/r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 19 at 13:53

























          answered Jan 18 at 23:20









          steeldriversteeldriver

          35.9k35286




          35.9k35286























              -1














              Used below method to achieve same



              sed "/USER CONSOLA/s/.*/&,!10.249.245.90,/g" filename


              output



              # gfhfhgfh
              gfhfghgfhgfhgfh
              MACs
              # access
              USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.249.245.90,
              /bin/false





              share|improve this answer



























                -1














                Used below method to achieve same



                sed "/USER CONSOLA/s/.*/&,!10.249.245.90,/g" filename


                output



                # gfhfhgfh
                gfhfghgfhgfhgfh
                MACs
                # access
                USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.249.245.90,
                /bin/false





                share|improve this answer

























                  -1












                  -1








                  -1







                  Used below method to achieve same



                  sed "/USER CONSOLA/s/.*/&,!10.249.245.90,/g" filename


                  output



                  # gfhfhgfh
                  gfhfghgfhgfhgfh
                  MACs
                  # access
                  USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.249.245.90,
                  /bin/false





                  share|improve this answer













                  Used below method to achieve same



                  sed "/USER CONSOLA/s/.*/&,!10.249.245.90,/g" filename


                  output



                  # gfhfhgfh
                  gfhfghgfhgfhgfh
                  MACs
                  # access
                  USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.249.245.90,
                  /bin/false






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 19 at 4:54









                  Praveen Kumar BSPraveen Kumar BS

                  1,464138




                  1,464138












                      Popular posts from this blog

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

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay