The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep question. saurabhsinha23 UNIX for Dummies Questions & Answers 3 12-11-2007 01:58 AM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 08:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-27-2006 01:56 AM
grep & sed question der Kopf Shell Programming and Scripting 1 11-22-2004 04:49 AM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 10:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-11-2006
raje17 raje17 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
grep question

hi all,

I need to grep for a string in a file which is in another string

For Ex:

This is the sample file

sample.txt

number 1234
name raje
passwd 1234
date 123
service 75
service 23

I have made a unix command like this, i am not sure this is correct or wrong. If any better way please share with me

$ grep -w "service" sample.txt > /tmp/supp_serv.txt | cat /tmp/supp_serv.txt | grep "75" > /tmp/sscode75.txt

In the output (sscode.txt) i have to get ONLY "service 75"

Thanks,
-raje..
  #2 (permalink)  
Old 04-11-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
grep "service" sample.txt | grep "75" > /tmp/sscode75.txt
If you can depend on there being a fixed number of spaces between "service" and "75"
- this assumes one space
Code:
grep "service 75" sample.txt > /tmp/sscode75.txt
  #3 (permalink)  
Old 04-11-2006
raje17 raje17 is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 2
Thanks for the fast reply.

I want to print the file name aswell in the sscode75.txt

When i use the either one of the command ( like grep "service" sample.txt | grep "75" > /tmp/sscode75.txt ) i get only "service 75" in the sscode75.txt

But i want to put the file name also like

"sample.txt service 75"
  #4 (permalink)  
Old 04-11-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
grep "service" /dev/null sample.txt | grep 75 > /tmp/sscode75.txt

Cheers
ZB
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0