Results 1 to 6 of 6

Thread: Creating shell script in ubuntu

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    Creating shell script in ubuntu

    Hello,
    There's a script that I can not conclude. In fact I would like to modify a file by inserting it a line. My script opens the file well, put the cursor at the correct line. I can not find how to insert my text line in this file automatically.
    Here is the beginning of my shell script
    Code:
    / bin / sh
    clear
    sudo apt-get install numlockx
    Any help on this is appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Creating shell script in ubuntu

    Hello,
    To insert a line in a text file, you must make your echo command and redirect it to this text file. It provides that:
    Here is the code
    Code:
    echo "test-f / usr / bin / numlockx & ">> / etc / gdm / Init
    Especially but>> not> by doubling the sign '>' you add to the end of a file, not putting one you crush what exists and it is already less cool.

  3. #3
    Join Date
    Dec 2009
    Posts
    213

    Re: Creating shell script in ubuntu

    Hello,
    Even i am interested in creating a shell script in ubuntu. Except for one small thing, I have a script and it give an error, the line starts at the end of file while I wish she starts to the 89th line. In addition it writes the 88 to the end of the line. So, if you have any solution for this then please let me know. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Creating shell script in ubuntu

    Hello,
    Yes, because your codes entire line was to be copied, do not put the 88 to the end. Otherwise I just look at this file and apparently you would insert your text before 'exit 0', I try to find how to do and I come back here. Also one tip apparently you must use the command 'sed', but the syntax is not so simple. If you need any more help regarding this topic then you can post here.

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Creating shell script in ubuntu

    Hello,
    To insert a line in a specific place in your file using sed, C normally done via:
    Here is the code
    Code:
    sed-i '1 iligne 'file.txt
    With that you insert text before the line which was given "address". In the previous code-i option allows you to write directly into the file so that tests on files before cans. Quoted on the specified line number before which it must be inserted (you can substitute 89), followed by the parameter i and the line was inserted. The last parameter is the name of the file you want to edit.

  6. #6
    Join Date
    Mar 2010
    Posts
    197

    Re: Creating shell script in ubuntu

    Hello,
    To insert a line in a specific place in your file using sed, C normally done via:
    Code:
    Code:
    sed-i '1 iligne 'file.txt
    Well, I managed to do it and it works, script was slightly modified as
    Code:
    sudo sed-i '88c text to insert '/ path / file
    the 'c' is to put a line without creating an extra line, that's all. In any case it works and it's great. By the way thanks for your help.

Similar Threads

  1. shell script SSH not working
    By Lilya in forum Software Development
    Replies: 9
    Last Post: 16-10-2010, 01:53 AM
  2. Creating array with Bash shell
    By Carnie in forum Operating Systems
    Replies: 5
    Last Post: 19-02-2010, 07:54 PM
  3. Shell script with sed
    By Ameeryan in forum Software Development
    Replies: 5
    Last Post: 23-12-2009, 02:29 PM
  4. Shell Script Formatting
    By abhi701 in forum Software Development
    Replies: 1
    Last Post: 04-07-2009, 04:30 PM
  5. Unix Shell Script
    By BlackSunReyes in forum Software Development
    Replies: 3
    Last Post: 12-08-2008, 01:57 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,711,664,758.12252 seconds with 17 queries