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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
SED Replace String Help prash184u Shell Programming and Scripting 2 01-22-2008 09:57 PM
Basic sed replace question fed.linuxgossip Shell Programming and Scripting 13 05-09-2007 09:42 AM
Replace string B depending on occurence of string A hemangjani Shell Programming and Scripting 1 12-05-2006 01:10 PM
How to replace within a string aukequist Shell Programming and Scripting 2 02-07-2006 03:42 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Nov 2006
Posts: 44
basic cat replace string

trying to exclude hostnames ending in "s" from a host file:

Code:
# cat hosts
ssef
ssefd
ssefsfff
ssefsfs
# for x in `cat hosts`; do echo "${x/*s}" ;done
ef
efd
fff

#

How can I echo/or not echo only 'ssefsfs' ??

thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
 sed -n "/s$/! s/s.*s//p" file
To print lines ending with s
Code:
sed -n "/s$/p" file
To print lines without s at end
Code:
sed -n "/s$/! p" file
Reply With Quote
  #3 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Nov 2006
Posts: 44
Quote:
Originally Posted by anbu23
Code:
 sed -n "/s$/! s/s.*s//p" file
To print lines ending with s
Code:
sed -n "/s$/p" file
To print lines without s at end
Code:
sed -n "/s$/! p" file
thanks, exactly what i need
Reply With Quote
  #4 (permalink)  
Old 02-18-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,454
with awk,

Code:
awk '{ if( substr($0, length, 1) !~ /s/ ) { print } }'  filename
Reply With Quote
  #5 (permalink)  
Old 02-18-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Erm.... grep

Code:
 grep '[^s]$' hosts
Cheers
ZB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0