The tag has no wiki summary.

learn more… | top users | synonyms

6
votes
2answers
3k views

Merge folders and replace files using CLI

I want to update some forum software and I'd like to test the upgrade process using CLI as a learning possibility. How do I merge contents of a folder into another folder and replace files?
5
votes
3answers
1k views

vim - how can i do a 'change word' using the current paste buffer

I have some text in my paste buffer, e.g. I did a yw (yank word) and now I have 'foo' in my buffer. I now go to the word 'bar' and I want to replace it with my paste buffer. To replace the text ...
5
votes
3answers
189 views

How to insert text after the last configuration line?

I have to insert a line into a configuration files automatically, but with the added caveat that it should be inserted before a multi-line footer comment and any preceding empty or whitespace-only ...
1
vote
1answer
366 views

How does one find and replace text with geany in all files in a directory?

I see this discussion: How does one find and replace text in all open files with geany? I want to find and replace all files in a directory. The method suggested in the answer, is very good to find. ...
5
votes
4answers
530 views

sed how to substitute when string has “http://” in it?

I have a file xx that has the following contents: @base_url = "http://dmstaffing-stage.herokuapp.com/" I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
5
votes
3answers
7k views

Use sed to find whole word and replace

I have the following block of text in a file: test3.legacy test4.legacy test3 test3.kami I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
1
vote
2answers
299 views

Search and replace full line in recursive files

I'm using: grep -n -H -o -R -e textword . List all file recursively under directory '.' with string 'textword' and show the file, line and only portion matching. I need to remove lines that ...
2
votes
2answers
8k views

How can I replace text after a specific word using sed?

I have a file named .ignore. In need to replace the projdir. For example: ignore \..* ignore README projdir Snake I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
4
votes
2answers
303 views

Why does this add spaces? echo “x ax” | sed 's/x\s*/x /'

I want to find a x, and replace the 0 or more following spaces (\s*) with just a single space. echo "x ax" | sed 's/x\s*/x /' For some reason, instead of replacing the spaces with the single space, ...
2
votes
1answer
905 views

How to fix networking driver boot load failure after replacing hardware?

After replacing the motherboard, which is the same as after replacing the network adapter interface hardware (NIC), our Debian 6.0.6 no longer loads the networking driver on boot. The manual approach ...
-1
votes
1answer
72 views

Replace AAA for BBB in file

Given I have a file with several words, how can I do the following: How can I replace AAA for BBB in a file with Unix?
3
votes
2answers
119 views

How to convert *text* to {\i text} with sed?

I would like to replace every occurrence of *text* into {\i text}. text *text* text *text* text *text* *text text text* text should become text {\i text} text {\i text} text {\i text} {\i text ...
2
votes
5answers
534 views

Replacing lines in files with file contents

I have several files which contain some PHP includes and I want to substitute them with the file contents. The file looks like foo <?php include("file1.php"); ?> bar baz <?php ...
2
votes
3answers
2k views

Substitute placeholders in template

Say I have a shell configuration file config like this: HOST=localhost PORT=8080 Now I have a template template like this: The host is <%= @HOST %> The port is <%= @PORT %> How do I ...
2
votes
2answers
222 views

Copying hashtag comments recursively within <blocks>

I have two files, one with blocks like <record> line1 line2 line3 #model bla bla bla </record> while the other file has exactly the same number of blocks, but without the hashtag ...
2
votes
1answer
480 views

Replace semicolons to commas between the quotes only [duplicate]

Possible Duplicate: Remove comma between the quotes only I'm trying to use awk function to replace the semicolons between quotes to comma and it is 98% ok for me, because I want to keep the ...
12
votes
4answers
16k views

Remove line containing certain string and the following line

I use this cat foo.txt | sed '/bar/d' to remove lines containing the string 'bar' in the file. I would like however to remove those lines and the line directly after it. Preferably in sed, awk or ...
1
vote
4answers
776 views

Replace text between brackets

I'm using awk '{ gsub(/BAR|WIBBLE/, "FOO"); print }' to replace text in data like: SOMETHING [BAR, WIBBLE] SOMETHING [BAR] This gives the desired result of: SOMETHING [FOO, FOO] SOMETHING [FOO] ...
6
votes
2answers
806 views

shell script/utility replace 2 byte unicode in binary file

I have many large Unicode files. I would like to replace each Unicode byte pair with a new Unicode byte pair. For example, the original file contains "C3 B9 C3 AB C3 B8 C3 B0" and I would like to ...
8
votes
3answers
2k views

How to replace current word under cursor in Emacs

How do I replace current word under cursor in Emacs? I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. ...
4
votes
3answers
179 views

Smart way to perform a similar replacement (not simple enough for diff) in multiple files?

I have a bunch of files (45, so too many to edit them manually without going crazy) which all require the same changes (as seen in the three diffs at the end of this question). Most tools used for ...
3
votes
2answers
223 views

Add info under specific line

I want to know how could I add files contain information under specific line in file. For example, I have file1.txt with the following lines: line 1 line 2 line 3 and file2.txt has the ...
5
votes
1answer
476 views

Emacs simple arithmetics in query replace

Is it possible to do the following in emacs: Query replace all numbers in a region by the number +n, for example if you have: 12 and 7 are nice numbers let n be 3, then it should transform to 15 ...
1
vote
2answers
480 views

How to find and replace files contents that match a pattern?

Suppose we have a folder named Project. I would like find each file in the folder that contains the pattern &$ at the function call. For example should replace: AnyFunction(&$arg); with ...
3
votes
1answer
3k views

How to do multiline search and replace text (delete) recursively

I want to go recursively through a directory and search for specific content in all files. The content should then be replaced if found. With a single line I would make something like this: find . ...
2
votes
3answers
12k views

Sed : Replace pattern on every second occurence?

Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to). ...
6
votes
4answers
124 views

Replace a line with the line that I have in the buffer in vi

I cc or dd to copy a line into my paste buffer. Then I go to a new location. I want to replace a line that I see. So I type p Down dd. Is there an easier way (fewer keystrokes)?
2
votes
2answers
638 views

remove only specific text occurrences from string using sed

I have a text file that contains many rows of this sort of thing: /*[17:51:27][1 ms]*/ UPDATE `country` SET `region_id` = '4' WHERE `country_id` = '36'; Is there a way that I can use sed to remove ...
2
votes
1answer
526 views

Duplicate selected words with sed and replace it

I have to modify a document containing xml data; one modification I couldn't set up with sed. I have to modify the following expressions from: <Bild ...
3
votes
2answers
489 views

When merging directories with similarly-named files, how do you ensure that only smaller+earlier files are replaced?

E.g., if you want to merge two directories with each other (by moving everything from directory 1 into directory 2), and both directory 1 and directory 2 have some files with the same name. Then how ...
0
votes
2answers
5k views

Replacing one test string with another in particular column

I would like to replace "CC" with "C" and "AA" with A" in a particular column of Tab delimited file (using awk probably).
1
vote
2answers
274 views

How to split vCards lines

Related to How to join vCards lines, vCard does a weird kind of line splitting: If a line contains more than 75 characters, insert a "CR, LF, space" sequence. Thus the following line: ...
2
votes
1answer
339 views

How to join vCards lines

vCard uses a special way to split long lines: At 75 characters, insert a DOS newline and a space. Joining therefore means to replace all occurrences of the sequence "CR, LF, space" with an empty ...
2
votes
1answer
269 views

Replace “<?php print t('Blabla'); ?>” to be “Blabla”

Lets say in file.php, there is lots of php print text: <?php print t('Blabla'); ?>, <?php print t('Text Here'); ?>, etc. What I need is to remove <?php print t(' and '); ?> of the ...
0
votes
1answer
138 views

How to replace text after the cursor location in VIM

Suppose I have one line: Linux is not_ Linux My cursor lies on the _ mark and I want to replace the second Linux to Unix,how can I do that in vim?
2
votes
2answers
2k views

regex replace text in xml file within node from the command line

I have an XML file and I would like to replace everything that is between the open and closing tag within multiple instances of the g:gtin node with nothing. Is this possible from the command line, ...
4
votes
4answers
991 views

Replace whole line in a file from command-line

I have a text file which has some contents similar to this: # General information about the project. project = u'Py6S' copyright = u'2012, Robin Wilson' # The version info for the project you're ...
5
votes
1answer
6k views

Replace using VIM, reuse part of the search pattern

I am working with VIm and trying to set up a search and replace command to do some replacements where I can re-use the regular expression that is part of my search string. A simple example would be a ...
5
votes
1answer
501 views

Conditional search and replace on a line in vim?

Let' say I want to comment and uncomment a line. I know I can :s!^!//! and then :s!^//!! Now what if I want this as an one-liner? Basically, if a line starts with // then remove it, else add ...
3
votes
2answers
2k views

use awk to replace parentheses?

How can I use awk to replace the parentheses in these 2 scenarios? Change empty parens to the word "None" 192.168.0.24,Up,() Remove parens to only host.domain.com is left ...
6
votes
3answers
5k views

Vim :s replace first N < g occurrences on a line

In vim, I sometimes have occasion to replace the first few occurrences of a match on a line, but not every one like g would. e.g.: a a a a a to b b b a a I know I could use ...
8
votes
1answer
473 views

Case-preserving search and replace in vim?

In vim, I know I can search with or without case sensitivity. But if I want to search for a string in either upper or lower case, and replace it with a replacement of the same case, is that possible ...
9
votes
11answers
9k views

How can I “cat” a file and remove commented lines?

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 ; ...
4
votes
2answers
2k views

Replacing identical NIC cards creates eth1 instead of using eth0 in Ubuntu

I changed out a NIC card that was the exact same make and model. The setup process for Ubuntu 11.04 was very seemless and easy so I figured it would be smart enough to setup up the replacement card. ...
2
votes
1answer
479 views

Replace complex string in several files

A hacker got into a web server and added this string (removed some characters for security purposes and added line breaks for readability) in all index.php files: <?php ...
-2
votes
1answer
299 views

Linux “rpl” command doesn't replace text [closed]

I'm using rpl program in linux to replace date( with pdate( in some files. But it says A Total of 0 matches replaced in 1 file searched. while grep output for date( is: ...
10
votes
3answers
10k views

Replace string with contents of a file using sed

I have two different files: File1 /home/user1/ /home/user2/bin /home/user1/a/b/c File2 <TEXT1> <TEXT2> I want to replace the <TEXT1> of File2 with the contents of File1 ...
3
votes
5answers
2k views

How to replace a list of placeholders in a text file?

I have a text (configuration) file, but the program that reads the file unfortunately doesn't allow using any kind of variables. So I'd like to use a preprocessor that replaces a set of placeholders ...
2
votes
3answers
888 views

Collapse repeating characters

Is there a more Bashist way than echo "$PWD//" | sed -e 's#//\+#/#g' to replace repeating slashes with a single one? Thanks Steven D, now there's a fully working function to find the longest common ...
5
votes
2answers
3k views

How does one find and replace text in all open files with kate?

How does one find and replace text in all open files with kate?