The UNIX and Linux Forums  


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
Problem with GREP. syndex Shell Programming and Scripting 2 07-11-2007 02:44 PM
grep problem asal_email2 UNIX for Dummies Questions & Answers 4 06-22-2005 09:49 PM
grep problem svennie UNIX for Dummies Questions & Answers 5 11-08-2004 04:29 AM
Grep Problem lesstjm Shell Programming and Scripting 2 10-27-2004 11:13 AM
Grep problem odogbolu98 Shell Programming and Scripting 3 02-18-2003 03:53 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-05-2008
balamv balamv is offline
Registered User
  
 

Join Date: May 2008
Posts: 24
Exclamation grep problem

Example:

bashwd
/home/balamv


bash:more test.txt
hello
hello-ssl
welcome
welcome-ssl
hi
bye
bye-ssl
seeyou

I want to get all the lines which contain ssl and also the one does not contain ssl.

Output should be like this.


hello-ssl
welcome-ssl
hi
bye-ssl
seeyou


Note if a line [ex. hello] has the ssl line, then get only ssl.

How to achieve this?
  #2 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
It's not really a grep problem, per se.


Code:
sed -n 's/-ssl$//p' test.txt | fgrep -vxf - test.txt

This finds all the -ssl lines, and removes the -ssl suffix, then removes any lines matching any of these lines (-ssl lines with the -ssl suffix removed) from the original file.
  #3 (permalink)  
Old 06-05-2008
balamv balamv is offline
Registered User
  
 

Join Date: May 2008
Posts: 24
No. THIS IS NOT GIVING THE OUTPUT AS EXPECTED.
hello-ssl
welcome-ssl
hi
bye-ssl
seeyou
  #4 (permalink)  
Old 06-05-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
No need to shout.
What output did you get?

The only possible problem I see with eras solution is if there is extra space after the "-ssl", but a slight modification fixes that:

Code:
sed -n 's/-ssl\s*$//p' test.txt | fgrep -vxf - test.txt

  #5 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
\s is not a standard sed expression; you could use space and tab inside [ ] brackets instead. But I don't see any trailing spaces in the original example. If there are significant spaces, please use code tags when posting a sample.
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 03:16 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