[Solved] Help to remove a line from a file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved] Help to remove a line from a file

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-16-2012
samnyc samnyc is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 13 October 2014, 4:46 PM EDT
Posts: 225
Thanks: 66
Thanked 3 Times in 3 Posts
[Solved] Help to remove a line from a file

Hi,

I just upgraded one my server to latest version RHEL, I have many users who will do SSH from another server. I wanted to update all of the users home directory and remove the security key. For example.
/home/XYZ/.ssh/known_hosts and remove this hostsname.
Please see below and advise. Thanks.



Code:
 
#!/bin/ksh -e
XYZ='ls -1 /home'  ## need to list each of the home directory
for USERS in /$XYZ/.ssh/known_hosts ' ## each users home directory.
do
sed 's/txus03/g'   ##  remove the line txus03, replace with nothing
done

Sponsored Links
    #2  
Old 11-16-2012
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 21 November 2014, 1:51 PM EST
Location: East Coast
Posts: 611
Thanks: 1
Thanked 176 Times in 162 Posts

Code:
find /home -name 'known_hosts' -exec sed -i -e 's/txus03//g' {} \;

The Following User Says Thank You to in2nix4life For This Useful Post:
samnyc (11-16-2012)
Sponsored Links
    #3  
Old 11-16-2012
samnyc samnyc is offline
Registered User
 
Join Date: Jan 2009
Last Activity: 13 October 2014, 4:46 PM EDT
Posts: 225
Thanks: 66
Thanked 3 Times in 3 Posts
Quote:
Originally Posted by in2nix4life View Post
Code:
find /home -name 'known_hosts' -exec sed -i -e 's/txus03//g' {} \;

wow, you make it so simple, I was trying to do all kinds of crazy things. Thank you so much.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] remove file extension babom Shell Programming and Scripting 7 09-26-2012 06:57 AM
[Solved] Rename file name / remove part of name borobudur UNIX for Dummies Questions & Answers 2 04-24-2012 06:00 PM
[Solved] Read a .gz file line by line without using gzcat aikhaman Shell Programming and Scripting 4 10-06-2010 02:25 AM
[Solved] Problem in reading a file line by line till it reaches a white line hakermania Shell Programming and Scripting 3 08-19-2010 12:37 PM



All times are GMT -4. The time now is 09:24 PM.