LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-03-2006, 10:40 PM   #1
3saul
Member
 
Registered: Aug 2004
Location: Brisbane, Australia
Distribution: Ubuntu/Fedora
Posts: 86

Rep: Reputation: 15
Difficult sed/awk question


I'm wanting to search a text file for a phrase. If it finds this phrase then it will return the line number that the phrase exists at. Is this possible?

Once I've found the line the phrase is on I then need to alter the text. I know I can just search for phrase and edit that but I also need the line number that it was originally at for another purpose.

Thanks.
 
Old 03-03-2006, 11:29 PM   #2
sipsipi
Member
 
Registered: Dec 2005
Location: Chicago
Distribution: Fedora and Redhat
Posts: 86

Rep: Reputation: 15
Way #1)
grep -in "phrase" filename.txt

-i = ignore case (maybe not needed)
-n = line number.

Way #2)
vi filename.txt
then /"phrase"
look in corner for line number.
Edit.

YAY!

Last edited by sipsipi; 03-03-2006 at 11:30 PM.
 
Old 03-04-2006, 02:49 AM   #3
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Please use more descriptive topics. "searching for strings, how to output line number(s)?" would be a much better topic--we'd know what your problem is about.

Also, difficulty is relative--I find playing the tuba and driving cars difficult, but I know of at least one person who finds it a lot easier than I do. So saying "difficult" in the subject line is only informative to people who now what you find difficult.

trying-to-help-us-in-helping-you-'ly yours, Jonas
 
  


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
A difficult SED question... 3saul Linux - Software 4 03-08-2006 09:05 PM
Yet another SED Question...but more difficult... 3saul Linux - Software 3 01-06-2006 03:15 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
sed or awk question - replace caps with small letters computera Linux - General 1 12-30-2003 04:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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