LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-20-2007, 06:11 AM   #1
bhargav_crd
LQ Newbie
 
Registered: Sep 2007
Posts: 8

Rep: Reputation: 0
Shell Script: Delete lines til string found or until particular string.


Hi frnds,

I want a shell command to do following task ( A bit urgent ).
I want to delete from 1'st line to the line contains particular string.
Ex:

file1.txt
==========================
abc def
ghi j
klm nop
r st
uv
wxyz
==========================

if my input is "klm", then my output should be
file1.txt
==========================
klm nop
r st
uv
wxyz
==========================

Say my input is "uv", then my output should be
file1.txt
==========================
uv
wxyz
==========================


A bit urgent.
Plzz consider.

sed/more will help???
i tried sed.

NOTE: I want to do same recursvely. Ned to check all files in current path.

Thx
Bhargav

Last edited by bhargav_crd; 12-20-2007 at 06:17 AM.
 
Old 12-20-2007, 07:46 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Please do not mark your threads as urgent for the following reasons:

1. Your thread has no priority over other threads created by members.
2. It's a free site, there's not guaranteed solution to answers, you might not even get a reply at times.
3. Using a more descriptive title of the actual question or problem will get you more exposure.

Basically, most members here helping people like you out of their own spare and free time will ignore threads that say urgent in them. There's no reason to ever mark your own questions as a higher priority than anyone else's seeking help here.

If you have any questions, please read the FAQ, Rules and this thread http://www.linuxquestions.org/questi...95#post1730795 that basically goes over how to properly title your thread.

I've edited your title to something more appropriate and descriptive.
 
Old 12-20-2007, 07:58 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
http://www.grymoire.com/Unix/Sed.html

Take a look at addresses---eg sed '1,34 d' would remove the first 34 lines
 
Old 12-20-2007, 11:14 PM   #4
bhargav_crd
LQ Newbie
 
Registered: Sep 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Dear trickykid,
I'm sorry for that.
And thanks.

Dear pixellany,
Thank you.
sed '1,34 d' is pure static way.
But i need dynamic way.
My input is string. not line numbers.

Thanks
Bhargav
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script- text file manip- delete everything before/after string justin99 Programming 9 11-20-2014 03:16 AM
String Manipulations in Shell Script ramakula@gmail.com Programming 15 04-19-2007 10:40 AM
Shell Script - String Replacement revof11 Programming 7 11-29-2005 06:38 AM
(shell script) string parsing kuru Programming 4 09-12-2005 07:59 PM
Shell script to find a particular string Prasun1 Linux - General 5 08-30-2005 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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