?
Solved

how to  overwrite an existing text  file in shell script ?

Posted on 2003-03-18
8
Medium Priority
?
2,085 Views
Last Modified: 2008-03-17
I would like to know how to overwrite an existing text file
as i wrote the script likethis ....>> /home/abc.txt.
However, the text file keeps appending texts without overwrite the exsting content at all.  According to what I read from the various sources,
it stated it should use > instead of >>. I tried it but it failed to execute.
Please help on this problem, thanks!
0
Comment
Question by:cat21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:girish_nair
ID: 8167664
Simply if you use
echo "hello" > /your_dir/abc.txt
On a command prompt it works fine.

HTH

0
 
LVL 1

Expert Comment

by:veeruns
ID: 8174726
use
>| to force overwriting
hope it helps
Ram
0
 

Expert Comment

by:DracoX
ID: 8177238
In addition to using a single > when trying to write the file, make sure you have permission to write to the directory itself, and not just the file.

0
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
LVL 1

Expert Comment

by:veeruns
ID: 8181051
ohh yeah right..of course..i thgt that was understood
0
 
LVL 2

Accepted Solution

by:
GP1628 earned 80 total points
ID: 8251333
in cases where you only have access to the file and not the directory, you can "empty out" the file by doing..

cp /dev/null /home/abc.txt

then the >> can append to the newly zero'd file.

Gandalf  Parker
0
 
LVL 1

Expert Comment

by:veeruns
ID: 8254784
yeah that would be a really good idea
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10102061
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: GP1628 {http:#8251333}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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