Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-21-2006, 03:26 AM   #1
Registered: Dec 2005
Posts: 48

Rep: Reputation: 15
how to delete the contents of a file using shell scripts

I want to delete some text from the file using shell script.
I am using redhat7.0 . Please help me to solve this problem.

thanks in advance.
Old 05-21-2006, 03:35 AM   #2
Registered: Jan 2004
Location: /lost+found
Distribution: Slackware 14.2
Posts: 849

Rep: Reputation: 33
You want to delete text from a text file? If so, you'll want to open and editor like vi or vim and delete the lines.

vi yourfile
To get a list of vi/vim commands visit this site. Hope that answered your question.
Old 05-21-2006, 04:54 AM   #3
Registered: Oct 2005
Location: Hannover, Germany
Distribution: Let there be Ubuntu... :o)
Posts: 573

Rep: Reputation: 32
> filename
Old 05-21-2006, 05:05 AM   #4
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
Originally Posted by sharad
I want to delete some text from the file using shell script.
I am using redhat7.0 . Please help me to solve this problem.
What kind of content deletion do you have in mind? Want the script to search and remove certain keywords? Or delete lines that include particular words? You need to be more specific if you want concrete help.
Old 05-22-2006, 04:45 AM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Sed is usually used for editing files. The name stands for Serial EDitor.
For tabular text, awk is often used.
Old 05-22-2006, 05:22 AM   #6
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Delete lines 1-6 from a file
sed '1,6d' oldfile > newfile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
unix shell script:How to delete the first line in a file?? rche3252 Programming 6 03-03-2010 07:32 AM
2 gigabyte /tmp directory..ok to delete contents pAn1k Linux - Newbie 3 09-02-2004 09:56 AM
How to delete a line from a text file with shell script programming Bassam General 1 01-28-2004 08:51 PM
Delete contents of the file, but not file? mikeshn Linux - General 9 05-28-2003 06:47 AM
Can't delete or list contents of an old kio_http cache,... JaseP Linux - General 3 06-09-2002 03:00 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration