Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find and replace from multiple files Post 303018603 by jim mcnamara on Monday 11th of June 2018 06:13:26 PM
Old 06-11-2018
I'm not sure your plan is the best but here is a suggestion, make a backup first even though there is garbage in there.:
If it is limited to php files (for example), then limit searching with find as step one, then use grep to see if the file is infected, and sed to remove bad strings - sed has to write to a tmp file which at the end of sed processing gets copied back and then re-set permissions/ownership.
psuedocode:
Code:
find /path/to/start  -type f -name '*php' |
while read fname 
do
   grep -q 'malware code pattern' $fname
   if [ $? -eq 0 ]; then
      sed 's/malware pattern//g' $fname  >/tmp/file
      mv /tmp/file $fname
      chown [required ownership] $fname
      chmod [required permissions] $fname 
   fi
done

This has the potential of breaking some code. It also depends on how well you did checking for malware, it could simply reinfect your system if you missed something.
Be sure to get a good backup once the system is running correctly.
This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace files in multiple folders

Hi there, I would like to write a script to automate the copy and renaming of files in multiple dir. I have a generic file named s253e.prb and would like to copy this to multiple dir and rename it. Example: Dir is AL-M1 and the prb file name is AL-M1.prb. I would like to be able to... (6 Replies)
Discussion started by: lodey
6 Replies

2. Shell Programming and Scripting

Find and Replace in multiple files (Shell script)

hi guys, Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do it ??? jatin (13 Replies)
Discussion started by: jatins_s
13 Replies

3. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies

4. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

5. Shell Programming and Scripting

awk find and replace in multiple files

Hi I use the following code to replace ‘.' with ‘N' in my files and keep both versions. awk '{ gsub(/\./,"N"); print }' file_0001.txt > path/to/new/dir/file_0001.txt I need help on how to apply the code to 100 files instead of doing them one file at a time. The files are labeled... (7 Replies)
Discussion started by: jdhahbi
7 Replies

6. UNIX for Dummies Questions & Answers

how to find and replace strings in multiple files

Hi All, Iam new to unix, I need to find string and replace it in the file name. Like text_123_0.txt,text_123_1.txt,text_123_2.txt. I need to search 123 and replace it with 234 . Is there any unix command to replace them in single command since i have 5 directories. So i need to go each and every... (0 Replies)
Discussion started by: etldeveloper
0 Replies

7. Emergency UNIX and Linux Support

Find, replace, file path in multiple files for Solaris 10

Guys I have a big issue that I need to get fixed ASAP however I can not seem to find a way to do it. We started to use zones with Solaris 10 at work and we moved a zone from a SIT box to a DEV box. Problem is the software we have installed is looking at a /lcl/sit/apps/ path and it needs to look... (5 Replies)
Discussion started by: LRoberts
5 Replies

8. UNIX for Advanced & Expert Users

linux find and replace in multiple files

Is there a reason why all of these examples of linux find and replace in multiple files use find and grep to pipe into sed or perl. Why not just use sed or perl directly with something like this? sed -i 's/echo/burnbaby/g' booboo*... (2 Replies)
Discussion started by: cokedude
2 Replies

9. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

10. Shell Programming and Scripting

Find and replace in multiple files

Hi, I have php files in main dir and sub dir's as well. I need to find "new mysqli('localhost', 'System', 'xxxxxx', 'System', '3306');" and replace as "new mysqli('localhost', 'unx_sys', 'yyyy', 'unx_sys', '3306');" I tried like: sed 's/new mysqli\(*\)\;$/new... (1 Reply)
Discussion started by: ashokvpp
1 Replies
mcx erdos(1)							  USER COMMANDS 						      mcx erdos(1)

  NAME
      mcx erdos - compute shortest paths in a graph

  SYNOPSIS
      mcx erdos [options]

      mcxerdos	is  not  in  actual  fact  a program. This manual page documents the behaviour and options of the mcx program when invoked in mode
      erdos. The options -h, --apropos, --version, -set, --nop, -progress <num> are accessible in all mcx modes. They are  described  in  the  mcx
      manual page.

      mcx  erdos  [-query  <fname>  (query input stream)] [-abc <fname> (specify label input)] [-imx <fname> (specify matrix input)] [-tab <fname>
      (use tab file)] [-o <fname> (output file name)] [--is-directed (input graph  is  directed)]  [--is-undirected  (input  graph  is	directed)]
      [-write-path  <fname>  (path  matrix file)] [-write-step <fname> (step matrix file)] [-h (print synopsis, exit)] [--apropos (print synopsis,
      exit)] [--version (print version, exit)]

  DESCRIPTION
      mcx erdos computes shortest paths in graphs.  It can read a graph either in label format with -abc or in native format with -imx.  It  reads
      pairs of node indices from an input stream, and for each pair outputs a data structure describing the full set of shortest paths between the
      two nodes.  Edge weights are not taken into account, so an edge always represents a unit step size between two  nodes  irrespective  of  its
      weight. A mode to compute shortest paths while taking into account edge weights will be implemented later as mcx dijkstra.

      Note  that  the  full set of shortest paths between two nodes in a graph can be described as a directed acyclic graph (DAG), and this is how
      mcx erdos operates. It is easy to construct graphs and node pairs for which the number of shortest paths between the two nodes becomes expo-
      nential in the size of the graph, whereas the lattice description is always garantueed to map to a subset of the graph edge set.

      By  default  it is assumed that the input graph should be treated as undirected. To this end a transformation step is applied to ensure that
      the graph in memory is undirected. It is possible to compute shortest paths in directed graphs by using --is-directed, and it is possible to
      omit  the  transformation  step  by using --is-undirected.  If the latter is specified while the input graph is in native format and in fact
      directed, results will be erroneous. This could in theory be mitigated by checking that the input graph is undirected. However,  the  reason
      to  use --is-undirected is simply to increase speed of operation, whereas such a check would be equally expensive as the transformation step
      that is omitted with --is-undirected.

      The input graph/matrix, if specified with the -imx option, has to be in mcl matrix/graph format. You can use label input	instead  by  using
      the  -abc option.  Refer to mcxio(5) for a description of these two input formats.  By default mcx erdos reads from STDIN and expects matrix
      format.  To specify label input from STDIN use -abc -.

  OPTIONS
      -query <fname> (query input)
	The name for the file from which queries are read.  A query consists of two white-space separated node indices or  two	white-space  sepa-
	rated labels. Labels can only be used if either -abc or -tab is specified.

      -abc <fname> (label input)
	The file name for input that is in label format.

      -imx <fname> (input matrix)
	The file name for input that is in mcl native matrix format.

      -o <fname> (output file name)
	The name of the file to write output to.

      -tab <fname> (use tab file)
	This  option causes the output to be printed with the labels found in the tab file.  With -abc this option will, additionally, construct a
	graph only on the labels found in the tab file.  If this option is used in conjunction with -imx the tab domain and the matrix domain  are
	required to be identical.

      --is-directed (compute directed shortest paths)
	The input graph is not transformed and assumed to be directed.	Shortest paths are computed taking this into account.

      --is-undirected (skip symmetrification step)
	The  input  graph  is not transformed and assumed to be undirected.  Shortest paths are computed on the assumption that the input is undi-
	rected. Use this option only if you are sure the input is undirected and need to have faster execution.

      -write-path <fname> (path matrix file)
      -write-step <fname> (step matrix file)
	The path matrix enumerates the nodes that take part in all shortest paths. The first list contains those nodes that lie at distance  1	of
	the  source  node, the second list contains nodes lying at distance 2, and so on.  The step matrix contains all the edges that make up the
	lattice of shortest paths between the two query nodes.

  SEE ALSO
      mcxio(5), and mclfamily(7) for an overview of all the documentation and the utilities in the mcl family.

  mcx erdos 12-068						      8 Mar 2012							mcx erdos(1)
All times are GMT -4. The time now is 03:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy