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
deleting lines using awk-best way? satnamx Shell Programming and Scripting 3 08-29-2007 07:24 PM
Deleting Lines from .CSV Files 009satya Shell Programming and Scripting 1 11-13-2006 03:30 PM
deleting lines ajnabi Shell Programming and Scripting 8 05-02-2003 11:50 AM
deleting lines supercbw High Level Programming 1 05-06-2002 12:53 PM
Deleting Multiple Lines with sed rambo15 Shell Programming and Scripting 1 02-16-2002 06:19 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 10-24-2008
Bandit390 Bandit390 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 19
Help deleting lines with SED.

I take the /etc/passwd file and print it out, but I only want the lines that end with sh.

I have
Code:
cat /etc/passwd | sed '/sh/!d'
Which prints out all lines that have sh somewhere in it.

So I added $, which I thought matches the ends on lines, but its not working, like for example I have have file "sshd:x:100:65534::/var/run/sshd:/bin/false", that does not end in sh
Code:
cat /etc/passwd | sed '/$sh/!d'
Any suggestions?
  #2 (permalink)  
Old 10-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,305
Using cat with sed is redundant:

Code:
sed -n 's/sh$/&/p' /etc/passwd
Regards

Last edited by Franklin52; 10-24-2008 at 05:18 PM.. Reason: misread the question
  #3 (permalink)  
Old 10-24-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink What about this?

> cat /etc/passwd | egrep -v "sh$"

or, depending on your system

> cat /etc/passwd | grep -v "sh$"

or, using sed

> cat /etc/passwd | sed '/sh$/d'
  #4 (permalink)  
Old 10-24-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,421
Exclamation

@joeyg, multiple UUOC !
  #5 (permalink)  
Old 10-24-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Unhappy

Quote:
danmero -- @joeyg, multiple UUOC !
Yep, I knew that after I did the three examples. Late in the day, and just following the syntax lead of the OP (original post). Copied/pasted what person orignally tried, then modified slightly to fix and give correct results.

All of them could've been in format
command <file_in

  #6 (permalink)  
Old 10-24-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
For those who do not know - UUOC = useless use of cat. Don't use cat when you can redirect a file into stdin of a command. If that gets repeated thousands of times in a script it eats system resources - like inside a loop.
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 06:27 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