Visit Our UNIX and Linux User Community


how to put a # in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to put a # in a file
# 1  
Old 12-19-2007
how to put a # in a file

Hello,

Sir's,

I would like to ask for help. This is my problem, i am working for a mbs for aix,hp-ux and solaris. And i am making a script that will automatically implement the said mbs.

For example it will automatically change the permmisions of /usr/bin, /etc/passwd and so on. . . .

Now the problem is, cat /etc/inetd

i want that if it will find the word pop3,smtpd and named. it will automatically assign # in the said line.

sample:
cat /etc/inetd
pop3
named
ftpd
nfs
smtpd


output:

#pop3
#named
ftpd
nfs
#smtpd
# 2  
Old 12-19-2007
Try this command

sed -e 's/pop3/#pop3/g' -e 's/named/#named/g' -e 's/smtpd/#smtpd/g' /etc/inetd

P.S: The above command will replace all pop3 content with "#pop3" similarly for other pattern as well.
# 3  
Old 12-19-2007
awesome dude Smilie
# 4  
Old 12-19-2007
but wait a sec,
i jsut want that i will only mark in the 1st column,pls see below :

#pop3 stream tcp nowait root /usr/sbin/pop3d pop3

not like this:

#pop3 stream tcp nowait root /usr/sbin/pop3d #pop3

thanks a lot
# 5  
Old 12-19-2007
Quote:
Originally Posted by invinzin21
Hello,

Sir's,

I would like to ask for help. This is my problem, i am working for a mbs for aix,hp-ux and solaris. And i am making a script that will automatically implement the said mbs.

For example it will automatically change the permmisions of /usr/bin, /etc/passwd and so on. . . .

Now the problem is, cat /etc/inetd

i want that if it will find the word pop3,smtpd and named. it will automatically assign # in the said line.

sample:
cat /etc/inetd
pop3
named
ftpd
nfs
smtpd


output:

#pop3
#named
ftpd
nfs
#smtpd
try this one .. Not tested

Code:
gawk '{
if($1 ~ "pop3" || $1 ~ "smtpd" || $1 ~ "named"){print "#" $0}        
    else { print $0 }
}' my_file

# 6  
Old 12-19-2007
it works thanks sir
# 7  
Old 12-19-2007
sed

Hi,

Hope this one works for you.

Code:
sed 's/\(named\)/#&/;s/\(nfs\)/#&/' filename


Previous Thread | Next Thread
Test Your Knowledge in Computers #236
Difficulty: Easy
The ARPANET was operated by the AT&T during the two decades of its existence, until 1990.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract data from a log file and put it in a file

Hi, I would like to seek your help for a script that will extract data from log file and put it in a file. Sample log file 2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH account: 123456789 aiSessionNumber: 660640464 mapName: xxx to yyy errorDesc: Translation Error:ErrorNumber : 993 ... (2 Replies)
Discussion started by: neverwinter112
2 Replies

2. Shell Programming and Scripting

Get Data From CSV File and put into a txt file

Hi Guys, File A I have File A as CSV Format.... No R SS MK Par value S AL A1 PKL123 Lo12 1 S AL A2 PKl123 Lo34 22 S AL A3 PkLK234 Lo67 -34 S AL A4 PkLK235 Lo09 120 S AL A5 PkLK236 Lo76 19 S AL A6 PkLK237 Lo44 -17 S AL A7 PkLK238 Lo90 2 S AL A8 PkLK239 Lo34 -9 I want file B like... (4 Replies)
Discussion started by: asavaliya
4 Replies

3. UNIX for Dummies Questions & Answers

put script into file

hi, ok having here some code like: #!/bin/bash echo " hello " # say hello to the user echo " $HOME " echo " $HOSTNAME " echo " $(uname) " echo " today is $(date) " echo " $(whoami) is currently logged in " now my question is how to change the code so that the info is not... (12 Replies)
Discussion started by: me.
12 Replies

4. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

5. Shell Programming and Scripting

Get a column from one file and put it in another

I have 2 files that I would need from one file the 3rd column and put into the second file. Preferably in KSH . For example file one has file1: Column 1 Column 2 Column 3 Column 4 Column 5 file2: Column 1 Column 2 Column 3 Column 4 Column 5 So take Column 3 and put into file1 making it... (4 Replies)
Discussion started by: bombcan1
4 Replies

6. UNIX for Dummies Questions & Answers

I want some selected data from first file and put into other file in specified format

I have a file with follwing content ---------------------------------- SCHEDULE XXXXXXXXX#JOBCOUNT ON EVERYDAY AT 0000 PRIORITY 50 SCHEDULE XXXXXXXXX#ABCDEFGH ON EVERYDAY AT 0001 PRIORITY 29 SCHEDULE... (5 Replies)
Discussion started by: shreyas
5 Replies

7. Shell Programming and Scripting

Put two lines into one from file

Hello, I have a script that generates the following file named /tmp/rfkill: rf55 pts/13 Jul 10 06:38 (10.72.11.44) 15782 pts/13 5:07 b rf56 pts/15 Jul 10 06:53 (10.72.11.9) 18552 pts/15 0:28 b rf55 pts/39 Jul 10 09:12 (10.72.11.44) 19354 pts/39... (4 Replies)
Discussion started by: raidzero
4 Replies

8. Shell Programming and Scripting

TOP out put to a file

How to copy a top output to some file...! i am getting a blank data only top << file1 (2 Replies)
Discussion started by: bullz26
2 Replies

9. UNIX for Advanced & Expert Users

Put strings around the file name

I have a file(old file) with names in it like Jolly Mirani Han Lee stuart Lloyd I want string to be added to these names . New file should look like 'jolly mirani' 'han lee' 'stuart lloyd' I tried using sed command but doesn't work for string but it do work for paranthesis. Can some one... (3 Replies)
Discussion started by: Jolly
3 Replies

10. UNIX for Dummies Questions & Answers

Take a file from the system and put on tape and reset the file to 0 bytes

:mad: I did this the other day but one of my support personnel removed my history so i could call it back up to remeber the exact command since i am air-headed at times. I am trying to take a 30 MEG file off the system and drop it to tape then i want to make the file go back to being 0 bytes so... (1 Reply)
Discussion started by: JackieRyan26
1 Replies

Featured Tech Videos