The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
2answers
53 views

How to insert text after a certain string in a file?

Right now I'm using echo "Hello World" >> file.txt to append some text to a file but I also need to add text below a certain string let's say "[option]", is it possible with sed? EG: Input ...
7
votes
3answers
429 views

How to remove a specific character in a string but only if there are no numbers in that line in Linux

I've been stumped with this seemingly simple-to-fix problem.. well, for a while. Here's example output from the file I need to edit: $cat file George Washington Geneva Convention 123,281,029 USD ...
0
votes
1answer
26 views

text replacing in data file with peculiar spacing

I have a text (.qdp) file with many data stored. In some rows, the data are too many to be on just one line. Then, the program that saves the data, use a minus sign (-) to go on the new line, and ...
5
votes
2answers
303 views

Remove unknown unicode character from textfiles - sed, other bash/shell methods

I need to search and replace all occurences of an unknown character in some files having the same name. Opening such files with vi, I read <91> code for that character. Opening them with nano, I ...
1
vote
1answer
50 views

Problem installing input-wacom-0.20.0

I run Linux Mint 14. I bought a wacom intuos pen&touch small tablet and my old driver (don't know which one, someone installed it for me...) does not support it. I did a little research and found ...
1
vote
1answer
34 views

Sed: search and replace a patten with special characters which has a arbitrary string in between

I have a load of nfo files which I want to make some global substitutions for some values within each file e.g. a.nfo has the value <set>Tonight&apos;s Menu ( June 2012 )</set> ...
1
vote
1answer
71 views

Replace spaces and tabs at the end of the line in all files

I need to replace all unwanted spaces in all files from the current directory and from directories from the current directory (recursive search). I define the unwanted spaces the spaces and tabs that ...
0
votes
1answer
102 views

Copy file while replacing text in it

I'm writing a script to publish a webapp. While copying files, I must replace a placeholder current_date in a file with the current date. I would start with something like this to define the date ...
0
votes
1answer
69 views

How to add parens around text

How can I use sed to replace text and also append to end of line for the match in question? I have a sed file which is doing many substitutions. One of them changes ~= to match( using /=\~/ ...
4
votes
3answers
249 views

how to emulate “replace a b b a” with a sed?

I am trying to emulate a replace command which swaps two characters, with a sed script, but the obvious choice: sed -e 's/a/b/g' -e 's/b/a/g' does no work. Can you point me how to do it correctly? ...
2
votes
1answer
27 views

Replace output occurrences

Let's say I have this output: 0001 0002 0003 0004 0005 and I want to replace the first two zeros (00) with (01). What is the simplest way to achieve this?
0
votes
0answers
10 views

using tops command to update NSLog statements in cocoa code

In my objective-c code base I have several NSLog statements. eg. NSLog(@"Here is the message without arguments"); NSLog(@"Here is the message with arguments: %s, %s","argument1","argument2"); Now ...
6
votes
2answers
109 views

How to report “sed” in-place changes

When using sed to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)? For instance, how can I change the command line ...
3
votes
2answers
311 views

Replace a pattern in a file with a long string

I'm writing a little shell script to generate a directory listing. To make the output easily customizable, the script just builds a HTML-table and than should replace a specific token in a template ...
1
vote
0answers
49 views

Automatic replacement of strings in gedit

I want to replace some strings defined by me in gedit, after a word has been completed and/or the document has been saved. For example \ðrac should be replaced with \frac How do I do this in gedit or ...
3
votes
5answers
162 views

How to grep, then search and replace on the output?

I have some output from iconv, e.g. $ iconv -l | grep ISO | head -5 CSISO4UNITEDKINGDOM// CSISO10SWEDISH// CSISO11SWEDISHFORNAMES// CSISO14JISC6220RO// CSISO15ITALIAN// durrantm:~ How can I change ...
7
votes
2answers
423 views

How could I use Bash to find 2 bytes in a binary file, increase their values, and replace?

I'm trying to find two bytes inside binary file, then increase value of those two bytes and replace them inside file. Those two bytes are on positions 0x82-0x83. For now on I have successfully ...
3
votes
2answers
308 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?
4
votes
3answers
177 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
167 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
156 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
313 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
2k 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
121 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 ...
0
votes
0answers
57 views

How to disable Dejavu sans at global level? And what font could be the substitute?

I'm fed up with one DejaVu Sans rendering bug, which I call "forever bug" (bug that gets it's problem somewhat negated or behavior changed between releases, but never fixed). I have problem with dot ...
2
votes
2answers
3k 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
266 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
587 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
60 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
114 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 ...
1
vote
5answers
348 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
770 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
180 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
292 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 ...
8
votes
4answers
8k 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
531 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
500 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 ...
4
votes
3answers
821 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
160 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 ...
2
votes
2answers
194 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 ...
4
votes
1answer
292 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
326 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
2k 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 . ...
1
vote
3answers
7k 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
121 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
400 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
368 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
390 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
3k 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
245 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: ...