LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2009, 04:56 PM   #1
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
bash; editting config files and replacing lines


My problem is in a script which i'm writing to help a total novice set up fluxbox etc. Basically, someone buys an eeepc, hoses an eeepc, needs help rebuilding.. after 2 days over the phone I decide a script is easier.

Now, the fluxbox config/init file contains the startup files and ends with
Code:
exec startfluxbox
This means everything needs to be prior to the 'exec' statement. My initial idea was just to use

Code:
value=$((`cat $fluxbox-config|wc -l`-1))
sed '$value i\hello' $fluxbox-config
but obviously this wont work. Is there a way of using a sort of

Code:
 sed '-1i\hello' $fluxbox-config
to do the second to last line?

or is my best best bet to stick a bit of python or perl in there?
 
Old 01-07-2009, 06:17 PM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Original Poster
Rep: Reputation: 70
never mind, I cheated and just used a hackish way of doing it

Code:
fluxboxconfig=/home/$USERNAME/.fluxbox/startup
value=$((`cat $fluxboxconfig|wc -l`-1))
top=`head -$value $fluxboxconfig`
echo $top "idesk&" `tail -1 $fluxboxconfig` > $fluxboxconfig
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
commands for bash script that handles files of varying number of lines BBFeltham Linux - Newbie 1 07-26-2008 10:18 AM
Replacing part (lines) of a file ( bash or perl ) zomane Programming 3 10-26-2007 04:10 PM
replacing blank lines bharatbsharma Programming 5 10-25-2007 08:44 AM
Replacing new lines (\n) from a file bkeeper Linux - Software 4 12-15-2005 02:13 AM
Copying linked files, replacing directories in bash scripts? ta0kira Programming 2 10-10-2004 04:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration