Adding or deleting an entry in /etc/inittab without using vi editrors or any editor.

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Adding or deleting an entry in /etc/inittab without using vi editrors or any editor.
# 1  
Old 04-05-2010
Adding or deleting an entry in /etc/inittab without using vi editrors or any editor.

Hi masters

Is there any way to edit or delete an entry in inittab file without using vi or any editors?

We can use commands instead or any shell script ..

If any one can help deeply appreciated

Thanks a lot

sai
# 2  
Old 04-12-2010
cat / head / tail

1) suppose your inittab has 10 lines, and you wish to delete the fourth (*) line:

Code:
$ head -3 /etc/inittab > firstpart
$ tail -6 /etc/inittab > lastpart
$ cat firstpart lastpart > /etc/inittab

(*) fourth line from the beginning, obviously (first line is number one).

2) now if you wish to replace the fourth line:

Code:
$ cat > mynew4 <<eot
your new line # 4 here
eot
$ cat firstpart mynew4 lastpart > /etc/inittab

ok ?

good luck, and success !

alexandre botao
<< botao {dot} org >>
# 3  
Old 04-12-2010
You can use also eg. sed, cut or tr as well. However it's rather 'modify' option ;-) Ex:

cp /etc/inittab /tmp
cat /tmp/inittab | sed 's/id:5/id:3/' > /etc/inittab

Regards,
-Artur.
# 4  
Old 04-12-2010
You can also do it in perl after making a backup of the file

Code:
#!/usr/bin/perl 
# or wherever your perl is

use File::Copy;
my $orig = "yourfile";
my $backup = "yourfile.bak";

copy($orig, $backup);

open(IN, "< $backup");
open OUT, "> $orig");

my $newsetting = "your new line";

while ($line = <IN>)
    {
        if($line =~ m#"$newsetting)
            {
                $newline = "$newsetting";
                print OUT "$newline\n";
            }
        else
            {
                print OUT "$line";
            }
    }
close(OUT);
close(IN);


Last edited by mark54g; 04-12-2010 at 03:26 PM.. Reason: Clean up braces, forgot to add file copy module below comments
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting duplicate glosses in a dictionary entry

I am working on an Urdu to Hindi dictionary and I have created the following file structure: Headword=Gloss1,Gloss2,Gloss3 i.e. glosses delimited by a comma. It so happens that in some cases (around 6000+ in a file of over 200,000+ the glosses are duplicated. Since this may be a... (3 Replies)
Discussion started by: gimley
3 Replies

2. Linux

How to add a entry in inittab?

Hi All, I am booting by Linux box with the run level 3 and it gets booted successfully. I want to execute a script once the system is up and running in the run level 3. I was trying to add a entry to /etc/inittab to execute my script once the system is up. I have added the below... (5 Replies)
Discussion started by: kalpeer
5 Replies

3. Shell Programming and Scripting

Searching for an entry and deleting the line

Hi Im trying to scan a file for certain entries and remove their corresponding lines completely. What I have now is this, for USER in user1 user2 user3 user4 do sed '/$USER/d' /etc/sudoers done However this doesn't remove the entries at all. Is there another way for this? Thanks... (2 Replies)
Discussion started by: bludhemn
2 Replies

4. Shell Programming and Scripting

Deleting Duplicates leaving the first entry

Hi, I need to delete duplicate records in a file that is around 30MB. Below is what I need. Below are the entries of input file and the output file that I need. Each section of input file is separated by an empty line. Some of these sections have duplicate uid values. I want to retain only one... (4 Replies)
Discussion started by: Samingla
4 Replies

5. Shell Programming and Scripting

Deleting file entry

Hello everyone, I want to compare the first line of a file(ABC) with that of a folder,XYZ(folder contents) and want that line to be deleted from the file(ABC) if that entry doesn't exist in the folder(XYZ) I want to put this in a loop. please can anyone help thanks (6 Replies)
Discussion started by: swasid
6 Replies

6. Solaris

inittab entry does not works

Hi, I have a solaris 10 server,which has a process running that communicates with other system.I have made following entry in the inittab file. PM15:s12345:respawn:/ncm/bin/communicator PM15 : Unique process ID s12345 : run levels respawn : if anytime the process... (2 Replies)
Discussion started by: asalman.qazi
2 Replies

7. HP-UX

Adding printer entry into host file

Hi relatively new to unix so sorry if this is a stupid question: How do i add a printer entry into the host file. I know how to add the printer using sam, but i am required to add the host file entry into /etc/hosts which i am unaware of how to do. Any help would be greatly appreciated. (2 Replies)
Discussion started by: Wade Gava
2 Replies

8. Shell Programming and Scripting

adding a host entry on another machine

I have written this small script to add an entry to a remote /etc/hosts file which needs to be run from our central admin box and is passed one parameter $1 <hostname> #!/bin/ksh echo "Which host entry would you like to add to $1" read host_to_add echo "what is the IP address?" read ip ... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. Shell Programming and Scripting

Adding entry into crontab in ksh program

Hi falks, I have the following ksh function ,which adding entry to crontab during ksh program running: { print "Go\c" >/dev/null 2>&1 print '0 0 * * * su - ias -c "/home/orca/core-${SCHEMA_NAME}/CLI/cleanup_BRMS.ksh"\c' >/dev/null 2>&1 print "\033:wq!" >/dev/null 2>&1 } | \crontab -e... (2 Replies)
Discussion started by: nir_s
2 Replies

10. Shell Programming and Scripting

Deleting double entry in a file

Hi, I am having almost the same problem as junior member 'oupsforum' (refer to subjuct "deleting double entry in a log file"), only that I am using Sun Sorlaris Unix which the uniq command does not has the flag -w. So I am not able to ignore certain portion of the line when the uniq doing the... (3 Replies)
Discussion started by: Wing m. Cheng
3 Replies
Login or Register to Ask a Question