Solved

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

Posted on 2014-04-06
4
548 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 34

Assisted Solution

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

Open in new window


HTH,
Dan
0
 
LVL 10

Assisted Solution

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

Assisted Solution

by:xeroxzerox
xeroxzerox earned 125 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 125 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now