LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-26-2008, 01:18 AM   #1
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Rep: Reputation: 0
Delete specific Range of lines Using sed , awk, grep etc.


hi,
My issue is that I want to delete a range of lines from a txt file Using shell scripting.For example in a file containing 100 lines, I want to delete only specific lines in the range of 11 to 29 .I can use any command for this purpose in shell script. Somebody please suggest a solution

line no. 10 contains
10 <Help
11 Name ="Maintenance Department"
12 Help="">
13 >Text
14 ...............
15 <F1
16 ...........
17 .........
18
19 <text
20 .........
21 ...........
22 <F1>
23 ...........
24 .........
25 <text
26 .........
27 ...........
28 </Help>
29 <Help
30 Name ="Clearing Department"
31 Help="">
32 >Text
33 ...............
34 <F1
35 ...........
36 .........


Is there anyone who can help me out
 
Old 03-26-2008, 01:54 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
If you mentioned WHICH lines in that range you'd like
to remove, maybe?




Cheers,
Tink

Last edited by Tinkster; 03-26-2008 at 12:15 PM. Reason: syg00 might be right ;}
 
Old 03-26-2008, 02:06 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,059

Rep: Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971Reputation: 971
Sounds like homework to me Tink ...
 
Old 03-28-2008, 08:01 AM   #4
joyds219
LQ Newbie
 
Registered: Mar 2008
Posts: 9

Original Poster
Rep: Reputation: 0
The command to be used was
sed '2,10d' a.org > b.txt
this would delete line ranging from 2 to 10 including them.
It looks so easy. but it came after a lot of research
 
Old 03-28-2008, 08:59 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by joyds219 View Post
The command to be used was
sed '2,10d' a.org > b.txt
this would delete line ranging from 2 to 10 including them.
It looks so easy. but it came after a lot of research
Congratulations!! Homework or not, you are on the path to total success. Look also at addressing by content---not just line number.
eg:
sed '/text/,/F1/d oldfile > newfile
 
  


Reply


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
sed or grep : delete lines containing matching text raj000 Linux - General 18 09-08-2012 09:38 AM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 09:00 AM
awk/sed to grep the text ahpin Linux - Software 3 10-17-2007 12:34 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM


All times are GMT -5. The time now is 10:21 AM.

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