LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 04-09-2012, 08:16 AM   #1
Shahid nx
Member
 
Registered: Jan 2012
Posts: 41

Rep: Reputation: Disabled
searching only particuler string?


Hello Sir/Hi Friend,
I have a process written in C++ using vi editor which is around 20,000 lines of code. In that we should not use standard output printf(). But for sake of testing and debugging i used printf function many side. So now before releasing the product i have to remove all printf statements. my problem is in my process i have used sprintf and TERR(gTrace,printf("----") like staements. So i have to go through each line manually to search printf statemenst. Means ultimately i want an expression or command which search all lines which starts with printf. PLEASE HELP ME OUT.

thanks in advance
 
Old 04-09-2012, 08:24 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,569
Blog Entries: 1

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
Try the following:
Code:
sed -n '/^printf/p' file
 
Old 04-09-2012, 08:24 AM   #3
manu-tm
Member
 
Registered: May 2008
Location: France
Distribution: Ubuntu, Debian
Posts: 239

Rep: Reputation: 23
grep -nr printf *
(only to search so sed is probably a better option)

Last edited by manu-tm; 04-09-2012 at 08:27 AM.
 
Old 04-09-2012, 08:31 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,569
Blog Entries: 1

Rep: Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026Reputation: 1026
An update to my previous example. If 'printf' is not exactly at the beginning of a line, it won't work. If you also have tabs/spaces preceeding 'printf' you might want to use:

Code:
sed -n '/^[[:blank:]]*printf/p' file

Btw, what are you changing 'printf' into? You might want to save yourself some time and let sed do the substitutions for you.
 
Old 04-09-2012, 08:42 AM   #5
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
You are using vi and vi can do this - no command line solution needed e.g.

Type:
Code:
:g/^\*sprintf/d
 
Old 04-09-2012, 08:53 AM   #6
Shahid nx
Member
 
Registered: Jan 2012
Posts: 41

Original Poster
Rep: Reputation: Disabled
@sycamorex: ooooooo..........Ya sir sed -n '/^[[:blank:]]*printf/p' file this command done my job my headach finish. Thanks alot to all
 
  


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
Searching for text string in all files ortizmj Linux - Newbie 2 03-03-2011 01:03 PM
Searching a partition for a string Completely Clueless Linux - Newbie 40 08-03-2009 11:45 AM
Searching a string from the file amty Programming 6 11-06-2008 07:04 AM
searching for char string containing a '/' cleopard Programming 3 08-14-2008 04:17 PM
Searching for a string krazykow Solaris / OpenSolaris 1 03-17-2005 11:55 AM


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