Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I add a line of text to the end of a file

Posted on 2014-04-06
4
Medium Priority
?
587 Views
Last Modified: 2014-04-06
I am using RHEL.  If I have a file a.a, and it contains the following:

first item
second item
third item

... and I want to add a line at the end of the file, and perform something like

concatenate  a.a  "fourth item"

and the result would look something like

first item
second item
third item
fourth item

(Note, this will requiree a CR)

What command would I use to perform this
0
Comment
Question by:Anthony Lucia
4 Comments
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 500 total points
ID: 39981526
echo 'fourth item' >> a.a

Open in new window


HTH,
Dan
0
 
LVL 10

Assisted Solution

by:santhoshu
santhoshu earned 500 total points
ID: 39981537
0
 
LVL 6

Assisted Solution

by:xeroxzerox
xeroxzerox earned 500 total points
ID: 39981553
hi,
various option you can use like..

$ sed -i '$ a\this is line 2 without redirection' test
then see file without opening
# cat test

2nd one
#echo 'hello' >> file.txt
0
 
LVL 17

Accepted Solution

by:
bigeven2002 earned 500 total points
ID: 39981555
Hello,

I typically use VI to edit text files.
vi a.a

Open in new window

In VI, it opens as read-only.  To edit, press I for insert.  Then it becomes editable.  Place the cursor at end of line 3, then press Enter for new line.  Add desired text.  Then press Shift+; to call a command line at bottom of file, then type wq and press Enter to save and close file.  "wq" stands for write;quit.

If you want to familarize yourself with all of VI's commands, see this link:

http://glaciated.org/vi/
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question