Skip to content

Tag: sed

Faster solution to compare files in bash

file1: and file2: I need find match file2 in file1 and print whole file1 + second column of file2 So ouptut is: My solution is very slow in bash: I am prefer FASTER any bash or awk solution. Output can be modified, but need keep all the informations (order of column can be different). EDIT: Right now it looks…

Match unknown substring with RegEx

How can I get an unknown substring with an regular expression? I know what’s before and after the wanted string but I don’t want the known part with in the result. Example text: I’m looking for ‘SOMETHINGHERE’ and ‘SOMETHINGELSE’ only. vocher_ and .db are always befor…

In bash got unwanted newlines after sed and cat >>

I’m trying to substitute some lines in /etc/hosts file with my script here: It searches e.g. for lines like and replaces the line (if it’s found) with a sed command to nothing, but adds afterwards e.g. to I’m having to do (?) this because my LAN network addresses are changing very often (exa…

Using sed with regex to replace text on OSX and Linux

I am trying to replace some strings inside a file with sed using Regular Expressions. To complicate the matter, this is being done inside a Makefile script that needs to work on both osx and linux. Specifically, within file.tex I want to replace with (xxx and yyy are just example text.) Note, xxx could contai…

Fastest way to extract pattern

What is the fastest way to extract a substring of interest from input such as the following? Desired output (i.e., the :-terminated string following the string MsgTrace(65/26) in this example): noop I tried the following, but without success: Answer grep by default returns the entire line when a match is foun…

Bash replacing text in file

I want to automate changes in a File. For example ;max_input_vars = to max_input_vars = 10000 in /etc/php5/cli/php.ini with a script. How can I do that? I know command sed will do something like that. Answer Try this command: