LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
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: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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 8 05-15-2009 07:40 PM
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


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