I have ~750 .php files in the same directory that contain the line  include("path/to/file.php");   I would like to change this line in every file to  require_once("path/to/file.php");   What would be an efficient method to do so? So far I have tried the following Sed command with no luck:   sed 's#include("path/to/file.php");#require_once("path/to/file.php");#' *.php
1394
Replacing strings in files based on certain search criteria is a very common task. How can I    replace string foo with bar in all files in the current directory? do the same recursively for sub directories? replace only if the file name matches another string? replace only if the string is found in a certain context? replace if the string is on a certain line number? replace multiple strings with the same replacement replace multiple strings with different replacements
25907
Original file claudio antonio claudio michele  I  want to change only the first occurrence of &quot;claudio&quot; with &quot;claudia&quot; so that I would get the following: claudia antonio claudio michele  I have tried the following: sed -e '1,/claudio/s/claudio/claudia/' nomi  The above command performs global substitution (it replaces all occurrences of 'claudio') . Why?
104899
I have a file that contains filenames with absolute path.  In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the variable name, the sed part doesn't work.  The sed part is to delete the pattern or for this matter, the path.   file=`echo $one_file | sed 's:/dir1/dir2/$VAR/last_dir/::'`
122379
I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far:   sed -i '/ * [^()] */d' *.c  This works when the comments are on the same line as an asterisk or backslash.   However it doesn't work when there is a commented line without a slash or asterisk.   I know sed goes line by line, I just don't know how to tell it to keep deleting until it sees a */.
54821
I know this question has probably been answered before.  I have seen many threads about this in various places, but the answers are usually hard to extract for me.  I am looking for help with an example usage of the 'sed' command.  Say I wanted to act upon the file "hello.txt" (in same directory as prompt).  Anywhere it contained the phrase "few", it should be changed to "asd".  What would the command look like?
70116
Suppose there are two files in web/ named foo.php and bar.php. The 1st line of foo.php is "sdajgeSTRINGdsad" and the 10th line of bar.php is "gdfhu98324STRING". The task is to first locate these two files, then delete 1st line of foo.php and 10th line of bar.php given that the specified string is "STRING".
12955
I want to append this text:  &lt;Directory "/var/www/*"&gt;     Order allow,deny     Allow from all     AllowOverride All &lt;/Directory&gt;   to the file /etc/apache2/apache2.conf  I have access via SSH but I don't know how to use VIM. I would like to do this via a command.
61922
I'm trying to search and replace a string in all files matched by grep: grep -n 'foo' * will give me output in the form: [filename]:[line number]:[text]  For each file returned by grep, I'd like to modify the file by replacing foo with bar.
65413
I'd like to know if there is a way that I could cat file like php.ini and remove all lines starting with ;  For example, if the file contained this:  ;   - Show all errors, except for notices ; ;error_reporting = E_ALL &amp; ~E_NOTICE ; ;   - Show only errors ; ;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; ;   - Show all errors except for notices ; error_reporting  =  E_ALL &amp; ~E_NOTICE   and I ran the correct command cat | {remove comments command}, then I would end up with:  error_reporting  =  E_ALL &amp; ~E_NOTICE   Note - I assumed that cat would be the best way to do this but I'm actually fine with the answer using another utility like awk, sed, egrep, etc.
22924
How can I search and replace text that contains / with sed?  I currently use the following command which doesn't work  sed -i "s/queue_directory = /var/spool/postfix-secondary/queue_directory = /var/spool/postfix-$newnumber/g" /etc/postfix-$newnumber/main.cf
100466
0:root@SERVER:/root # echo "something" | sed -e 's/^/\t/g' tsomething 0:root@SERVER:/root #    AIX/ksh .. why doesn't it works? I just want to put a "tab" before every line!
31542
I need to replace single quotes with double quotes AND double quotes with single quotes in over 600 files. I've been reading various topics most of the day. I am hampered by only knowing some basic shell scripting commands and an unfamiliarity with regexp.   Below is a sample file I've made a bit generic.     some text KEYWORD_1 table name column = "string" AND column = "string"     Additional text           .           .           .    some text KEYWORD_2 text 'text in quote' etc.    I only want to change the quotes on the 2 lines with KEYWORDs. I can't guarantee the keywords are always going to be first line and last line. I need my solution to find the keyword and change all the quotes on that line only.   I tried some things I found in sort of similar questions on this forum, including a meta on SED. I tried to figure out how to use this command: sed -i 's/foo\(.*baz\)/bar\1/' file. According to that topic the command, "Replaces foo with bar only if there is a baz later on the same line." My keyword is not later on the same line its at the beginning and I couldn't make it work for me.   I also tried ex -sc 'g/DEL/s/ALF/BRA/g' -cx file that didn't do anything. I'm assuming it can't be executed from the command line. I really don't want to open each of 600 files.  At one point I tried, grep KEYWORD_1 file | sed -i "s/'/\"/g" file Of course, that changed all the quotes in the file not just the one line.   I'm betting the solution is simple and I just can't see it. How can I do this?     As requested my desired output is:  some text KEYWORD_1 table name column = 'string' AND column = 'string'     Additional text           .            .           . some text KEYWORD_2 text "text in quote" etc.
15914
I want to insert 5 blank lines after every line in my input file.  foo.txt:  line 1 line 2 line 3   out.txt:  line 1      line 2      line 3          ...   Solaris 5.10, nawk or sed.
38971
Is there an option or tool that will allow me to change the default naming convention for files copied into the same directory in Windows (XP) and above.  e.g. from: Copy of {name}.{ext} to: {name}.{ext}.copy  Currently:  original_file.php Copy of original_file.php   Desired:  original_file.php original_file.php.copy   This would make finding/working with duplicated files much easier (they auto-sort together) and the filetype (by extension) changes thus it can't accidentally "break" something (e.g. if it were a *.java file, upon compiling I would get errors)
27692
Suppose I have a document with multiple include or input statements  \input{fileA} \input{fileB}   etc.   Is there an easy way to generate a single .tex file where \input{fileA} is replaced by the actual content of fileA etc. without copying it manually?
117282
I am trying to append and prepend text to every line in a .txt file.  I want to prepend: I am a   I want to append:  128... [}  to every line.  Inside of a.txt:  fruit, like bike, like dino, like   Upon performing the following command:  $ cat a.txt|sed 'I am a ',' 128... [}'   it does not work how I want it to. I would really want it to say the following:  I am a fruit, like 128... [} I am a bike, like 128... [} I am a dino, like 128... [}
5261
I've been looking around sed command to add text into a file in a specific line. This works adding text after line 1:  sed '1 a\   But I want to add it before line 1. It would be:  sed '0 a\   but I get this error: invalid usage of line address 0.  Any suggestion?