LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-05-2013, 02:12 PM   #1
Hoxygen232
LQ Newbie
 
Registered: Jan 2013
Posts: 28

Rep: Reputation: Disabled
bash - delete lines that starts with one particular lettere from a file


Hi,

What I want to do is:
I have a "file.txt" like this:
Code:
hi
mom
zzz
the
pasta
tomorrow
night
zorro
zheta
zing
I need to delete all words that starts with 'z', so after remval it will be:
Code:
hi
mom
the
pasta
tomorrow
night
so I need to delete from the same file which I read from, and there must not be empty lines after removal.

Is it possible?
thanks a lot

Last edited by Hoxygen232; 02-05-2013 at 02:34 PM.
 
Old 02-05-2013, 02:17 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Maybe by means of something like this?
Code:
sed -i '/^z/d' file
 
Old 02-05-2013, 02:19 PM   #3
Hoxygen232
LQ Newbie
 
Registered: Jan 2013
Posts: 28

Original Poster
Rep: Reputation: Disabled
great, it works perfect thanks
 
  


Reply

Tags
bash, bash scripting, unix


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
how to copy some lines in a file and delete these lines after gartura Linux - General 1 07-20-2010 08:55 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 06:18 PM
[SOLVED] Vi or Bash,way to delete everything but first N#lines ADxD_7 Programming 7 08-11-2009 03:16 PM
Need a bash shell script which will delete lines from file scjohnie Linux - Newbie 1 09-13-2008 08:51 PM
Can't delete a file that starts with - vtrac Linux - Software 4 04-17-2006 05:25 AM


All times are GMT -5. The time now is 12:27 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration