Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-08-2009, 04:23 AM   #1
LQ Newbie
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
How to delete certain lines from lots of files in the same directory?

Hello everyone,

I want to delete 2 lines from each file in a certain directory (and all subdirectories). I was wondering if there is a simple command to accomplish this.
Thanks for any help,
Old 12-08-2009, 05:26 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
what have you tried? hint: use find to find your files. as for deleting lines, there are variety of tools you can use, eg awk, sed , or even the shell.
Old 12-08-2009, 06:41 AM   #3
Registered: Jan 2009
Distribution: Fedora, CentOS, NetBSD
Posts: 115

Rep: Reputation: 17
I recommend that you use a shell script with sed,

Give us some more information about what you're trying to accomplish and I'll help you out with the script.

Are you trying to delete lines at particular Line numbers? Do these lines have the same text in all files? please be specific.
Old 12-08-2009, 08:17 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
sed "$num,+1d" filename
(deletes 2 lines, starting with $num)


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 delete lines and insert another line in some xml files using a shell script? luananeko Linux - Newbie 1 07-20-2009 10:53 PM
Unable to delete the lines in xml FILES ragavendran31 Linux - Newbie 1 01-19-2008 02:24 PM
delete lines from files bharatbsharma Programming 5 10-25-2007 09:43 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 10:19 AM
md5sum on a directory with lots of files. solarmax Linux - Software 5 08-11-2005 06:22 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:44 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