Results 1 to 4 of 4

Thread: Script to insert new line in a file in linux

  1. #1
    Join Date
    Jul 2009
    Posts
    87

    Script to insert new line in a file in linux

    Hi pals, I need help for creating a script. I have a file which has a lot of contact numbers. I have to update this file sometimes every minute or sometimes once a day. So to update and insert a new contact [or a new line] i have to open the file, then will have to search for the tag which says insert here, then update the file and then write it. Is there a simple script to do it more quickly? Please help guys...

  2. #2
    Join Date
    Apr 2008
    Posts
    3,267

    Re: Script to insert new line in a file in linux

    Suppose you file name is abc and there is a file xyz which has point "<-- insert here -->" you can directly add the contents of abc below the indication. Use the following code :
    Code:
    perl -pi -e 's/^(<-- insert links here -->)/$1."\n".`cat zzz`/e' yyy
    Hope this works...

  3. #3
    Join Date
    Nov 2005
    Posts
    3,026

    Re: Script to insert new line in a file in linux

    You can create a perl script. Pearl script is great when it comes to working with text files. See example script :
    Code:
    while (<STDIN>) {
    print; # prints the line to STDOUT
    if (/\<-- insert text here --\>/) {
    print "something to print\n"; #to add what you want
    }
    
    }

  4. #4
    Join Date
    Jul 2009
    Posts
    87

    Re: Script to insert new line in a file in linux

    Thanks for the replies guys... Will try it out and get back to you... Thanks again..

Similar Threads

  1. New data to the first line in *.csv file via VB Script
    By Conus in forum Software Development
    Replies: 2
    Last Post: 12-06-2012, 11:04 AM
  2. To insert a horizontal line in Word
    By Balamani in forum Windows Software
    Replies: 3
    Last Post: 21-10-2009, 07:04 PM
  3. How to insert new line in message box
    By Corona in forum Software Development
    Replies: 3
    Last Post: 11-08-2009, 01:27 PM
  4. How to Insert line break in XML
    By Suzane in forum Software Development
    Replies: 2
    Last Post: 07-07-2009, 01:00 PM
  5. Script insert date in the name of my file
    By Viensterrr in forum Software Development
    Replies: 4
    Last Post: 31-10-2008, 07:18 PM

Tags for this Thread

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
  •  
Page generated in 1,713,279,268.11834 seconds with 17 queries