LinuxQuestions.org
Review your favorite Linux distribution.
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 03-04-2007, 11:25 PM   #1
aress
LQ Newbie
 
Registered: Mar 2006
Posts: 11

Rep: Reputation: 0
Replacing multiple lines with null


Hi,

I want to replace few lines of malicious code fron php and html file with null. The code is found to be added at multiple places in a file.
Could anyone please suggest me ?

Thanks.
aress
 
Old 03-05-2007, 01:18 AM   #2
aress
LQ Newbie
 
Registered: Mar 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Hi,

Is there a way we can find the line number from a file matching soem pattern. I want to work on those line numbers.

Regards,
aress
 
Old 03-05-2007, 01:56 AM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
use grep, it can scan a file for a pattern and output the line, and line number. Dont know how to replace multiple line tho, probably something like awk, possibly sed.
 
Old 03-06-2007, 08:47 AM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Code:
while :
do
  RT:^)M grep
  sleep $TIME
done
where TIME varies from minutes to weeks depending on circumstances.


Seriously, grep is one of the most useful text processing commands in the *nix CLI arsenal. Its options are numerous & powerful & it pays to refresh your memory of them periodically.

Same for sed & even more so for awk. With awk check the info system for the deep stuff. (Hint: Konqueror can display info system pages as html -- put "##<command>" in its address bar.)

In the case or your Q, if you use sed or awk, you may not need grep as both can operate only on lines matching a regex.
 
  


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
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
Replacing new lines (\n) from a file bkeeper Linux - Software 4 12-15-2005 02:13 AM
replacing specific lines in a text document stellarmarine1 Linux - General 1 09-07-2004 02:34 PM
ISDN multiple lines schimmelpilz Linux - Newbie 1 02-24-2004 05:39 PM
Multiple redundant WAN lines. hubergeek Linux - Networking 8 07-25-2003 09:27 AM

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

All times are GMT -5. The time now is 02:54 PM.

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