Professional Web Applications Themes

Appending a string after a designated test - UNIX Programming

Hello there! How do I append a string ("<dir>/usr/X11R6/lib/X11/fonts/bangla</dir>" say) at the end of a designated line in an existing ASCII text file using a Shell Script? Like at first, it will search for a line of strings ("<dir>/usr/share/fonts</dir>" say) in a text file. Then it will append some texts after that said line. Yes, I wanted to modify "/etc/fonts/fonts.conf" with a shell script which will look like the modified section below afterwords. Any help would be appreciated. -----------------Content of Original file---------- <dir>/usr/X11R6/lib/X11/fonts/Type1</dir> <dir>/usr/share/fonts</dir> <------- search for this line and append. <dir>~/.fonts</dir> --------------Modified Section Below--------------- <dir>/usr/X11R6/lib/X11/fonts/Type1</dir> <dir>/usr/share/fonts</dir> <dir>/usr/X11R6/lib/X11/fonts/bangla</dir> <dir>~/.fonts</dir> Thanks ...

Sponsored Links
  1. #1

    Default Appending a string after a designated test

    Hello there!

    How do I append a string ("<dir>/usr/X11R6/lib/X11/fonts/bangla</dir>"
    say) at the end of a designated line in an existing ASCII text file
    using a Shell Script? Like at first, it will search for a line of
    strings ("<dir>/usr/share/fonts</dir>" say) in a text file. Then it
    will append some texts after that said line.

    Yes, I wanted to modify "/etc/fonts/fonts.conf" with a shell script
    which will look like the modified section below afterwords. Any help
    would be appreciated.


    -----------------Content of Original file----------

    <dir>/usr/X11R6/lib/X11/fonts/Type1</dir>
    <dir>/usr/share/fonts</dir> <------- search for this line and append.
    <dir>~/.fonts</dir>

    --------------Modified Section Below---------------

    <dir>/usr/X11R6/lib/X11/fonts/Type1</dir>
    <dir>/usr/share/fonts</dir>
    <dir>/usr/X11R6/lib/X11/fonts/bangla</dir>
    <dir>~/.fonts</dir>


    Thanks in advance.
    Raqueeb Hassan
    Congo
    Sponsored Links
    Raqueeb Guest

  2. #2

    Default Re: Appending a string after a designated test

    On 9 Feb 2004 21:57:24 -0800, Raqueeb Hassan <com> wrote: 

    One way:

    sed -f scriptfile inputfile

    scriptfile:

    /<dir>\/usr\/share\/fonts<\/dir>/a\
    <dir>/usr/X11R6/lib/X11/fonts/bangla</dir>

    (no blank lines)

    AC

    --
    ed(1)
    Check out the original tutorials by Brian W. Kernighan:
    ----- http://tinyurl.com/2uprx -----
    If it's good enough for BWK, it's good enough for me.
    Alan Guest

  3. #3

    Default Re: Appending a string after a designated test

    In article <google.com>,
    com (Raqueeb Hassan) wrote:
     

    sed
    '\|<dir>/usr/share/fonts</dir>|s|$|<dir>/usr/X11R6/lib/X11/fonts/bangla</
    dir>|' infile > outfile

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  4. #4

    Default Re: Appending a string after a designated test

    On Tue, 10 Feb 2004 01:50:47 -0500, Barry Margolin <mit.edu> wrote: 
    >
    > sed
    > '\|<dir>/usr/share/fonts</dir>|s|$|<dir>/usr/X11R6/lib/X11/fonts/bangla</
    > dir>|' infile > outfile
    >[/ref]

    I didn't realize you could do that with sed!

    But although that seems to be what he wants from the paragraph above,
    it's not what he shows in the example:



    -----------------Content of Original file----------

    <dir>/usr/X11R6/lib/X11/fonts/Type1</dir>
    <dir>/usr/share/fonts</dir> <------- search for this line and append.
    <dir>~/.fonts</dir>

    --------------Modified Section Below---------------

    <dir>/usr/X11R6/lib/X11/fonts/Type1</dir>
    <dir>/usr/share/fonts</dir>
    <dir>/usr/X11R6/lib/X11/fonts/bangla</dir>
    <dir>~/.fonts</dir>



    AC

    --
    ed(1)
    Check out the original tutorials by Brian W. Kernighan:
    ----- http://tinyurl.com/2uprx -----
    If it's good enough for BWK, it's good enough for me.
    Alan Guest

  5. Moderated Post

    Default Re: Appending a string after a designated test

    Removed by Administrator
    Alan Guest
    Moderated Post

  6. #6

    Default Re: Appending a string after a designated test

    In article <sK%Vb.22226$news.pas.earthlink.net>,
    Alan Connor <yyy> wrote:
     

    If you're referring to the appended text being on the next line rather
    than at the end of the matching line, I thought it might have been his
    posting software wrapping the line.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  7. #7

    Default Re: Appending a string after a designated test

    On Tue, 10 Feb 2004 02:59:48 -0500, Barry Margolin <mit.edu> wrote: 
    >
    > If you're referring to the appended text being on the next line rather
    > than at the end of the matching line, I thought it might have been his
    > posting software wrapping the line.
    >[/ref]

    A possibility that *I* should have considered. But it seems to me he posted
    the example precisely because he knows his English is less than perfect
    (though it sure seems fine to me) and append CAN refer to a line as well as
    a string....

    Well, we've covered all the bases, anyway.

    Thanks for adding the new phrase to my sed vocabulary, Barry.


    :-)

    AC

    --
    ed(1)
    Check out the original tutorials by Brian W. Kernighan:
    ----- http://tinyurl.com/2uprx -----
    If it's good enough for BWK, it's good enough for me.
    Alan Guest

  8. #8

    Default Re: Appending a string after a designated test

    Thanks very much both of you for the help. Indeed, nice solutions.
    I'll try it now. Basically I was trying to make a rpm where I need to
    edit that /etc/fonts.conf file. I'll insert a line just after a
    designated line and remove that after uninstallation. Any more ways to
    do that?

    Thanks again for the help.

    Raqueeb Hassan
    Congo
    Raqueeb Guest

  9. #9

    Default Re: Appending a string after a designated test

    com (Raqueeb Hassan) writes:
     

    Always think twice before automatically modifying configuration
    files. Whatever you do, at least save a backup of the old file.

    --
    Måns Rullgård
    se
    Måns Guest

  10. #10

    Default Re: Appending a string after a designated test

    On 10 Feb 2004 05:02:11 -0800, Raqueeb Hassan <com> wrote: 


    There are more ways than you can shake a stick at.

    Mans is right about the backup.

    To remove the line with Ed use this syntax:


    ed -s inputfile <<HHH
    g/regex/+1d
    wq
    HHH


    Later,

    AC

    --
    ed(1)
    Check out the original tutorials by Brian W. Kernighan:
    ----- http://tinyurl.com/2uprx -----
    If it's good enough for BWK, it's good enough for me.
    Alan Guest

  11. #11

    Default Re: Appending a string after a designated test

    Thanks all of you.

    It works nicely!

    Thanks.

    Raqueeb Hassan
    Congo
    Raqueeb Guest

Similar Threads

  1. Placing multiple files at once into pre-designated places
    By Stacey_Bertrand@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 12
    Last Post: November 14th, 05:08 PM
  2. Client Vars Repeatedly Fill Up Designated DB
    By Fletch702 in forum Coldfusion Server Administration
    Replies: 2
    Last Post: November 28th, 08:57 PM
  3. Appending to a string?
    By JakeFlynn in forum Macromedia ColdFusion
    Replies: 6
    Last Post: June 2nd, 01:24 PM
  4. how do i test a string has certain characters?
    By FlashAsh99 webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 4
    Last Post: January 30th, 03:08 AM
  5. Appending to an array
    By Thomas in forum Ruby
    Replies: 5
    Last Post: December 12th, 02:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139