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
Removing a file name (-T-G1) bobo UNIX for Dummies Questions & Answers 3 03-05-2008 11:26 AM
removing a line from a file and then placing into another file iago UNIX for Dummies Questions & Answers 1 09-09-2007 01:46 AM
Use "read" with a text file with comments mbarberis Shell Programming and Scripting 3 03-30-2005 02:24 AM
removing file vbaskar UNIX for Advanced & Expert Users 5 02-12-2002 04:43 PM

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 05-28-2008
skully skully is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 46
removing comments from file

I'm doing manual way to add and remove "#" on etc/services.
Is there anyway I can modify the file using awk or sed or any other program.

I use vi to modify /etc/services for enabling telnet , the problem is I don't know how to do it automatically in script.

production state:
#telnet

maintenance state:
telnet

production state:
#telnet

Thanks.
  #2 (permalink)  
Old 05-28-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,951
i've moved the thread to scripting cause it's not a solaris problem...
  #3 (permalink)  
Old 05-28-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Insert the hash in front:

Code:
sed 's/^telnet.*23/\#&/g' /etc/services > /tmp/alt_services.tmp
cp -p /tmp/alt_services.tmp /etc/services
Removing the hash:

Code:
sed 's/^\#\(telnet.*23\)/\1/g' /etc/services > /tmp/alt_services.tmp
cp -p /tmp/alt_services.tmp /etc/services
  #4 (permalink)  
Old 05-29-2008
skully skully is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 46
hi zaxxon,
During the file overwrite process. Will there by any impact ?
  #5 (permalink)  
Old 05-30-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Nope, there usually is no impact when overwriting the file. But you have to write it 1st into some temporary file and then cp or mv it over the original. Doing so, it is usually good to have copy of the former original before you modified.

May I ask what this is good for or is the services and telnet just an example?
  #6 (permalink)  
Old 06-02-2008
skully skully is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 46
telnet is just an example. server is tighten by previous admin and i need to chmod and modify here and there just to make it work.
  #7 (permalink)  
Old 06-02-2008
ThobiasVakayil ThobiasVakayil is offline
Registered User
  
 

Join Date: May 2006
Posts: 64
grep -v "^#" /etc/services > /tmp/alt_services.tmp
Closed Thread

Bookmarks

Tags
solaris

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 11:39 AM.


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