LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-26-2009, 09:34 AM   #1
roadrash
LQ Newbie
 
Registered: Jan 2007
Location: Huntingdon, U.K.
Distribution: Ubuntu, Mint
Posts: 24

Rep: Reputation: 0
Adding line of text to start of file


In a script i am working on, I need to be able to add the line of text "echo 1 > /proc/drive/acerhk/wirelessled beore the "exit 0"statement of the file contents below. How can I do this?

Quote:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will exit 0 on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0
 
Old 10-26-2009, 10:04 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Code:
sed -i.bkup '/^exit 0/i echo 1 > /proc/drive/acerhk/wirelessled' file.txt
If you're using a non-gnu version of sed you'll probably have to move the replacement text down to a second line.
 
Old 10-26-2009, 07:40 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
assuming you only have one exit 0 in your file

Code:
awk '!/^#/&&/exit/{print "echo 1 > /proc/drive/acerhk/wirelessled";print;next}1' file
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding lines of text to beginning of a text file BillKat Programming 2 01-19-2009 10:40 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:09 AM.

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