LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-12-2004, 08:52 AM   #1
pheasand
LQ Newbie
 
Registered: Sep 2004
Posts: 7

Rep: Reputation: 0
bash programming-append single line to end of file


If I had a file .. /etc/group for example, how can I append a single line to the end of group? I've browsed the docs for sed and awk, and while sed seems to be the correct tool for the job, I can't locate an example of a single line append. Also, there isn't any single 'append' command for bash that I know of. I have a man page for an append command but it is a TCL built in command and not an executable. Any ideas?


-pheasand
 
Old 12-12-2004, 09:06 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
The >> will append to the end of a file ....

echo this is a test >> /home/myfile.txt
 
Old 12-12-2004, 09:13 AM   #3
pheasand
LQ Newbie
 
Registered: Sep 2004
Posts: 7

Original Poster
Rep: Reputation: 0
Solved it myself.

While looking through more sed docs I found:
cat inFile | sed '$a/Text to append' > outFile

which appends: "Text to append" after the last line of text in inFile

-pheasand
 
Old 01-12-2006, 06:59 PM   #4
massysett
LQ Newbie
 
Registered: Nov 2005
Location: Silver Spring, Maryland USA
Distribution: SUSE Linux 10.0
Posts: 17

Rep: Reputation: 1
Good tip--one typo, though: if you're using GNU sed, that should be a backslash.

Using this I put together a pipeline that allows me to decrypt a text file using gpg, add something to it, and re-encrypt it again--all without writing any decrypted files to disk:

gpg --decrypt testfile2.asc | sed '$a\blah blah blah' | gpg --yes -ear omari@foo.com --output testfile2.asc
 
Old 02-28-2014, 09:41 AM   #5
rahil khera
LQ Newbie
 
Registered: Sep 2009
Posts: 14

Rep: Reputation: 0
How to append in a file of type proc_fs. When my application calls the write function of proc file, it over-writes previous contents. I have tried O_APPEND, although it is working with normal file but not with the proc_fs file.
 
  


Reply

Tags
bash



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
No new line at end of file? What does this mean? BajaNick Programming 12 05-19-2014 08:39 PM
Deleting empty line at end of text file in BASH human2.0 Linux - General 8 04-01-2009 02:44 AM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 09:42 AM
line of programming that keeps giving a syntax error at end of input mshinska Programming 1 10-03-2005 08:49 PM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 09:28 AM

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

All times are GMT -5. The time now is 07:30 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