LinuxQuestions.org
Review your favorite Linux distribution.
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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: 21,099

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
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: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration