Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [SOLVED] editing text via shell script?

  1. #1
    Join Date
    May 2008
    Location
    England
    Beans
    155
    Distro
    Ubuntu 8.04 Hardy Heron

    [SOLVED] editing text via shell script?

    I have a bit of time on my hands, and I've decided to add a few more linux skills to my belt (I'm an old hand, but I'm fairly competent) and I was thinking about making a shell script to remove apps that come as default under ubuntu and adding my own apps.

    I can do all of this, however I wondered how I would go about adding lines to text files (primarily sources.list to add repos for apps like cinelerra and playonlinux).

    My plan is to have the script in three parts, one to remove stuff, the second to edit text files, add 3rd party repos, and then the third part to install everything, and it was just the second part I was having difficulty with.

    Can anyone shed some light on the issue?

    regards,
    Civ
    HP DV6-3085EA, AMD Phenom P920

  2. #2
    Join Date
    Oct 2005
    Location
    Jacksonville, FL
    Beans
    29,420

    Re: editing text via shell script?

    Code:
    sudo nano -Bw /etc/apt/sources.list
    <Ctrl>x to exit and Y to save it.
    In the world of Linux, who needs Windows and Gates...

    Got most of my golden beans at an auction on eBay (with a couple of free drinks).

  3. #3
    Join Date
    Jun 2007
    Location
    Greater Boston
    Beans
    1,586
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: editing text via shell script?

    Have a look at basic unix/linux tools and bash commands.

    I'd start with sed, but don't stop there. You can do a lot by prompting users from shell scripts and also manipulating parts of files and reasembling them into new files.
    cmn

  4. #4
    Join Date
    Sep 2008
    Location
    Korea
    Beans
    938
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: editing text via shell script?

    Quote Originally Posted by taurus View Post
    Code:
    sudo nano -Bw /etc/apt/sources.list
    <Ctrl>x to exit and Y to save it.
    That's not very useful if he wants it to be in a script.
    The command you are looking for is
    Code:
    echo deb include repository here >> /etc/apt/sources.list

  5. #5
    Join Date
    May 2008
    Location
    England
    Beans
    155
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: editing text via shell script?

    so if I wanted to add
    deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted universe
    then I'd use
    Code:
    echo deb include "deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted"  here >> /etc/apt/sources.list
    ?
    HP DV6-3085EA, AMD Phenom P920

  6. #6
    Join Date
    Sep 2008
    Location
    Korea
    Beans
    938
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: editing text via shell script?

    Quote Originally Posted by C!V!NT View Post
    so if I wanted to add


    then I'd use
    Code:
    echo deb include "deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted"  here >> /etc/apt/sources.list
    ?
    No, sorry, that was ambiguous. You would just write

    Code:
    echo deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted >> /etc/apt/sources.list
    When you type in
    Code:
    echo Hello world
    then the string hello world will be printed on the screen. If you use the output redirection operator >> then you can have it printed elsewhere, in this case into a file.

  7. #7
    Join Date
    Oct 2005
    Location
    Jacksonville, FL
    Beans
    29,420

    Re: editing text via shell script?

    Quote Originally Posted by Idefix82 View Post
    No, sorry, that was ambiguous. You would just write

    Code:
    echo deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted >> /etc/apt/sources.list
    Sorry to inform you but that would not work unless you log in as root. Got to use sudo.
    In the world of Linux, who needs Windows and Gates...

    Got most of my golden beans at an auction on eBay (with a couple of free drinks).

  8. #8
    Join Date
    Sep 2008
    Location
    Korea
    Beans
    938
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: editing text via shell script?

    Quote Originally Posted by taurus View Post
    Sorry to inform you but that would not work unless you log in as root. Got to use sudo.
    You are right, thanks! But the OP will need to run his script with sudo anyway if he wants to install and uninstall software.

  9. #9
    Join Date
    Oct 2005
    Location
    Jacksonville, FL
    Beans
    29,420

    Re: editing text via shell script?

    Quote Originally Posted by C!V!NT View Post
    so if I wanted to add


    then I'd use
    Code:
    echo deb include "deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted"  here >> /etc/apt/sources.list
    ?
    Look at my #2 post on how to edit your /etc/apt/sources.list and once you're in /etc/apt/sources.list, just add this line to the end of it.

    Code:
    deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted universe
    In the world of Linux, who needs Windows and Gates...

    Got most of my golden beans at an auction on eBay (with a couple of free drinks).

  10. #10
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: editing text via shell script?

    In addition to /etc/apt/sources.list, /etc/apt/sources.list.d/*.list is also read, so I usually leave /etc/apt/sources.list alone and create a new file for third party repositories.

    E.g.:
    Code:
    echo "deb http://packages.medibuntu.org hardy free non-free" | sudo tee -a /etc/apt/sources.list.d/medibuntu.list

Page 1 of 2 12 LastLast

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
  •