Problem in making a script
Nils Kassube
kassube at gmx.net
Wed Jun 29 12:53:49 UTC 2011
amritpal pathak wrote:
> On Wed, Jun 29, 2011 at 7:46 AM, Nils Kassube <kassube at gmx.net> wrote:
> > amritpal pathak wrote:
> > > > How can i do it in the script?
> > > >
> > > > well i found i can accept user's input by using read command
> > > > in scripting .but still i have another problem.
> > > >
> > > I have to edit the config file i.e I want that
> > >
> > > input given by the users will be replace by config file's entries
> > > at particuler line.
> > > please tell me how to replace user's input with config file's
> > > particuler line's stuff?
> > >
> > > i am using gedit text editor.
> >
> > If you want to do it with a script, gedit isn't the right tool. Use
> > sed instead which is made for this task. Here is once more the
> > link to the sed manual:
> >
> > <http://www.gnu.org/software/sed/manual/html_node/index.html>
> >
> > If you need further assistance, please tell us how you know which
> > line to replace. Is it a particular line number or a text pattern
>
> particuler line number.
In this case I'll prefer the head and tail commands (I'm too lazy to
read the sed manual). This should do the trick - set the variables
accordingly before you call this untested snippet:
TEMP=$(mktemp)
head -n $(($LINENUM - 1)) "$CONFFILE" > "$TEMP"
echo "$USERINPUT" >> "$TEMP"
LEN=$(cat "$CONFFILE"|wc -l)
tail -n $(($LEN - $LINENUM)) "$CONFFILE" >> "$TEMP"
mv "$TEMP" "$CONFFILE"
Nils
More information about the ubuntu-users
mailing list