LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-11-2008, 10:13 AM   #1
daemon_14
Member
 
Registered: Jul 2003
Location: Mesa, AZ
Distribution: CentOS 5 (Cisco Apps), Ubuntu Server (8.10), Ubuntu Desktop (8.10)
Posts: 46

Rep: Reputation: 15
display all text beginning at <string>


i have a question regarding file searching/parsing within linux.
i have been looking through some log files and i have several strings that i am looking for. i know that i could cat the files and pipe to grep, but the lines are generally next to each other. it would be much easier if i could cat the file, search for a string (grep etc.) and then have it begin at line of the text i searched for.

i have looked at man pages and tutorials, but haven't found a solution. anyone out there have any insight?

q.
 
Old 11-11-2008, 10:40 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
It's not totally clear what you want to do...

It sounds like you want to have an output which begins with the first matching line and then continues to the end of the file.

Try this:
Suppose you want to search on the pattern "stuff" and then print that line and everything after:

sed -n '/stuff/,$p' filename

This is using an "address range" in sed---ie print everything from the line containing "stuff" up to the end of the file ($).
 
Old 11-11-2008, 11:12 AM   #3
daemon_14
Member
 
Registered: Jul 2003
Location: Mesa, AZ
Distribution: CentOS 5 (Cisco Apps), Ubuntu Server (8.10), Ubuntu Desktop (8.10)
Posts: 46

Original Poster
Rep: Reputation: 15
works well. thanks for the help.

is there any way that i can apply this to something like dmesg (tried, but sed expects a file name) or am i limited to only files?

q.
 
Old 11-11-2008, 01:57 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
You can pipe the output of something into any command that expects an input stream.

eg:
dmesg|grep <pattern>
dmesg|sed '<expression>'

A good place to start learning this stuff is "Bash Guide for Beginners", by Machtelt Garrels. Free at http://tldp.org

Also really good tutorials here:
http://www.grymoire.com/Unix/
 
Old 11-11-2008, 03:36 PM   #5
daemon_14
Member
 
Registered: Jul 2003
Location: Mesa, AZ
Distribution: CentOS 5 (Cisco Apps), Ubuntu Server (8.10), Ubuntu Desktop (8.10)
Posts: 46

Original Poster
Rep: Reputation: 15
right, i understand that i can pipe the output of dmesg into grep and use regex for my filtering. that isn't an issue.

as you have pointed out, i can use sed to search through a file from an occurrence through the eof.
my question was if that can be duplicated when i search through something like dmesg rather than through a local file. if not, it is fine; i can simply parse through everything by hand.

for those who are familiar with cisco ios commands, i am trying to accomplish something similar to

dmesg | begin <string>

(the "| begin" is a command in ios which searches through the output for the first instance of <string>. when <string> is encountered, it will show the line including <string> and then will continue to display the rest of the output as normal).

q.
 
  


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
Add text to the beginning of file names xebix Linux - Newbie 5 10-02-2008 12:43 AM
Easy string/text manipulation/indentation for restructured text brianmcgee Linux - Software 1 04-22-2008 08:27 PM
Display text string on root window LocoMojo Linux - Desktop 2 03-03-2007 09:15 AM
Add Text to Beginning of 200 Files dougp23 Linux - Newbie 3 10-30-2006 03:01 PM
writing text to the beginning of a file linuxmandrake Linux - Newbie 3 03-26-2006 10:55 PM

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

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