Facebooktwittergoogle_plusredditpinterestlinkedinmail

Deleting Lines Containing Specific string from multiple files recursively

Syntax:

grep -Rl "STRING" /directory/path/ | xargs sed -i "/STRING/d"

Example:

Below example delete lines containing @license tag from src/main/php directory all files recursively

grep -Rl "@license" src/main/php | xargs sed -i "/@license/d"

Option Description:

-R or –dereference-recursive

For each directory operand, read and process all files in that directory, recursively, following all symbolic links.

-l or –files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of each file stops on the first match. (-l is specified by POSIX.)

sed, short for “stream editor”, allows you to filter and transform text.

sed -i Edit files in place

Deleting Lines Containing Specific string from multiple fileshttp://techieroop.com/wp-content/uploads/2016/02/deleting-line-containing-some-string-using-sed.pnghttp://techieroop.com/wp-content/uploads/2016/02/deleting-line-containing-some-string-using-sed-150x150.png Roopendra Vishwakarma LinuxTricks and Tips
Deleting Lines Containing Specific string from multiple files recursivelySyntax: grep -Rl 'STRING' /directory/path/ | xargs sed -i '/STRING/d' Example:Below example delete lines containing @license tag from src/main/php directory all files recursivelygrep -Rl '@license' src/main/php | xargs sed -i '/@license/d'Option Description:-R or --dereference-recursiveFor each directory operand, read and process all files in...
Deleting Lines Containing Specific string from multiple files recursively<strong>Syntax:</strong> <pre><code>grep -Rl "STRING" /directory/path/ | xargs sed -i "/STRING/d"</code></pre> <strong>Example:</strong>Below example delete lines containing @license tag from src/main/php directory all files recursively<pre><code>grep -Rl "@license" src/main/php | xargs sed -i "/@license/d"</code></pre>Option Description:<strong>-R</strong> or <strong>--dereference-recursive</strong>For each directory operand, read and process all files in that directory, recursively, following all symbolic links.<strong>-l</strong> or <strong>--files-with-matches</strong> Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning of each file stops on the first match. (-l is specified by POSIX.)<b>sed</b>, short for "stream editor", allows you to <em>filter</em> and transform <em>text</em>.<strong>sed -i</strong> Edit files in place
(Visited 223 times, 15 visits today)
Facebooktwittergoogle_pluslinkedinrss