LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2011, 11:59 AM   #1
theemptyone
LQ Newbie
 
Registered: Sep 2010
Posts: 8

Rep: Reputation: 0
File Manipulation help..


I have to manipulate several hundred servers via a satelite script push.. and i'm trying to figure out how to remove two lines from inittab.

Does anyone have any idea on how to verify if the line is there.. then cut the correct line from the inittab with bash?

My thought is to cat -n | grep <what i need deleted>.. cut the number.. then find a way to delete that line from the file..

Any help would be greatly appreciated.
 
Old 05-27-2011, 12:15 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
If your line is so unique that you can grep it without getting unwanted results, it is no problem to delete that. Try it like this:
Code:
grep -v <what you need deleted> /etc/inittab > new_inittab
For more information have a look at
Code:
man grep
 
Old 05-27-2011, 01:57 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
You can also use sed.

Cut out a line 5:

Code:
sed '5d'
Cut out lines 5-10:

Code:
sed '5,10d'
Cut out a line containing a regex:

Code:
sed '/pattern/d'
You can also use sed's -i option to edit the file "in-place" (i.e. rewrite the original file with the edited version).
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
File-Manipulation calexander Linux - Newbie 5 05-15-2010 02:07 AM
File manipulation? hadimotamedi Linux - Newbie 13 05-12-2010 02:50 PM
File manipulation in C kalimat Programming 1 05-05-2010 08:47 AM
file name manipulation chocolatetoothpaste Linux - Software 19 04-03-2006 10:18 AM
file manipulation with c C.Aymen Programming 2 09-01-2005 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration