<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Howto: Linux command line utilities for removing blank lines from text files</title> <atom:link href="http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/feed/" rel="self" type="application/rss+xml" /><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/</link> <description>Every answer asks a more beautiful question.</description> <lastBuildDate>Fri, 10 Feb 2012 19:55:56 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: rceny</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-65491</link> <dc:creator>rceny</dc:creator> <pubDate>Sun, 11 Dec 2011 07:02:58 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-65491</guid> <description>Hi all,
Is there a way to add an empty line for every 5 lines of data using grep?
line1
line2
line3
line4
line5
(empty line)
line6
line7
line8
line9
line10
(empty line)</description> <content:encoded><![CDATA[<p>Hi all,</p><p>Is there a way to add an empty line for every 5 lines of data using grep?</p><p>line1<br
/> line2<br
/> line3<br
/> line4<br
/> line5<br
/> (empty line)<br
/> line6<br
/> line7<br
/> line8<br
/> line9<br
/> line10<br
/> (empty line)</p> ]]></content:encoded> </item> <item><title>By: anicka</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-64940</link> <dc:creator>anicka</dc:creator> <pubDate>Mon, 28 Nov 2011 13:58:42 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-64940</guid> <description>Hello!
Little fix in this BASH script:
#!/bin/bash
#!/bin/sh
files=&quot;/home/tiger/test_moduls/*.txt&quot;
for i in $files
do
sed &#039;/^ *$/d&#039; $i &gt; $i.out
mv  $i.out $i
done
Good Luck! :-)</description> <content:encoded><![CDATA[<p>Hello!</p><p>Little fix in this BASH script:</p><p>#!/bin/bash<br
/> #!/bin/sh<br
/> files=&#8221;/home/tiger/test_moduls/*.txt&#8221;<br
/> for i in $files<br
/> do<br
/> sed &#8216;/^ *$/d&#8217; $i &gt; $i.out<br
/> mv  $i.out $i<br
/> done</p><p>Good Luck! :-)</p> ]]></content:encoded> </item> <item><title>By: pj</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60694</link> <dc:creator>pj</dc:creator> <pubDate>Wed, 13 Jul 2011 10:45:14 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60694</guid> <description>Hi all,
I don&#039;t if is the right to post this issue,
is there any way to dump the new insert data to a textfile with shell script, for ie. after insertion to the mysql database execute the shell script to append and append the new record?
thanks</description> <content:encoded><![CDATA[<p>Hi all,</p><p>I don&#8217;t if is the right to post this issue,<br
/> is there any way to dump the new insert data to a textfile with shell script, for ie. after insertion to the mysql database execute the shell script to append and append the new record?</p><p>thanks</p> ]]></content:encoded> </item> <item><title>By: pj</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60686</link> <dc:creator>pj</dc:creator> <pubDate>Wed, 13 Jul 2011 07:51:43 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60686</guid> <description>correction
&#039;; done testdb.pl  &quot;&gt;testdb.pl&quot;</description> <content:encoded><![CDATA[<p>correction<br
/> &#8216;; done testdb.pl  &#8220;&gt;testdb.pl&#8221;</p> ]]></content:encoded> </item> <item><title>By: pj</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60685</link> <dc:creator>pj</dc:creator> <pubDate>Wed, 13 Jul 2011 07:50:21 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60685</guid> <description>while IFS= read -r line; do    echo &quot;$line&quot; &#124; sed -e &#039;s/-//g&#039; -e &#039;s/://g&#039; &#124; awk &#039;{ print $1$2 &quot; &#124; &quot; substr($0, index($0,$3))}&#039;; done testdb1.pl;</description> <content:encoded><![CDATA[<p>while IFS= read -r line; do    echo &#8220;$line&#8221; | sed -e &#8216;s/-//g&#8217; -e &#8216;s/://g&#8217; | awk &#8216;{ print $1$2 &#8221; | &#8221; substr($0, index($0,$3))}&#8217;; done testdb1.pl;</p> ]]></content:encoded> </item> <item><title>By: pj</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60684</link> <dc:creator>pj</dc:creator> <pubDate>Wed, 13 Jul 2011 07:48:46 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60684</guid> <description>Thanks for fast reply,
when I run this shell script
# while IFS= read -r line; do    echo &quot;$line&quot; &#124; sed -e &#039;s/-//g&#039; -e &#039;s/://g&#039; &#124; awk &#039;{ print $1$2 &quot; &#124; &quot; substr($0, index($0,$3))}&#039;; done testdb1.pl;
the file output is below: the line 1 not remove and added datetimemessage, is there any way to remove the line 1 which is &quot;datetimemessage &#124; datetime	message&quot;
datetimemessage &#124; datetime	message
20110713134535 &#124; Hello World of War Craft
20110713134843 &#124; This is a Test  of text</description> <content:encoded><![CDATA[<p>Thanks for fast reply,</p><p>when I run this shell script<br
/> # while IFS= read -r line; do    echo &#8220;$line&#8221; | sed -e &#8216;s/-//g&#8217; -e &#8216;s/://g&#8217; | awk &#8216;{ print $1$2 &#8221; | &#8221; substr($0, index($0,$3))}&#8217;; done testdb1.pl;</p><p>the file output is below: the line 1 not remove and added datetimemessage, is there any way to remove the line 1 which is &#8220;datetimemessage | datetime	message&#8221;</p><p>datetimemessage | datetime	message<br
/> 20110713134535 | Hello World of War Craft<br
/> 20110713134843 | This is a Test  of text</p> ]]></content:encoded> </item> <item><title>By: Tryme</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60683</link> <dc:creator>Tryme</dc:creator> <pubDate>Wed, 13 Jul 2011 07:30:07 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60683</guid> <description>Type
&lt;pre&gt;echo &#039;2011-07-13 13:45:35 Hello World of War Craft&#039;  &#124; sed -e &#039;s/-//g&#039; -e &#039;s/://g&#039; &#124; awk &#039;{ print $1$2 &quot; &#124; &quot; substr($0, index($0,$3))}&#039;&lt;/pre&gt;
Result:
&lt;pre&gt;20110713134535 &#124; Hello World of War Craft&lt;/pre&gt;
You need to process the file using while loop:
&lt;pre&gt;
while IFS= read -r line
do
echo &quot;$line&quot; &#124; sed -e &#039;s/-//g&#039; -e &#039;s/://g&#039; &#124; awk &#039;{ print $1$2 &quot; &#124; &quot; substr($0, index($0,$3))}&#039;
done &lt; &quot;input.txt&quot;
&lt;/pre&gt;
There may be a better solution to reduced awk, but I&#039;m too lazy to try it out ;)</description> <content:encoded><![CDATA[<p>Type</p><pre>echo '2011-07-13 13:45:35 Hello World of War Craft'  | sed -e 's/-//g' -e 's/://g' | awk '{ print $1$2 " | " substr($0, index($0,$3))}'</pre><p>Result:</p><pre>20110713134535 | Hello World of War Craft</pre><p>You need to process the file using while loop:</p><pre>
while IFS= read -r line
do
   echo "$line" | sed -e 's/-//g' -e 's/://g' | awk '{ print $1$2 " | " substr($0, index($0,$3))}'
done &lt; &quot;input.txt&quot;
</pre><p>There may be a better solution to reduced awk, but I&#8217;m too lazy to try it out ;)</p> ]]></content:encoded> </item> <item><title>By: pj</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60681</link> <dc:creator>pj</dc:creator> <pubDate>Wed, 13 Jul 2011 06:44:52 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-60681</guid> <description>I would like to know how i can write a shell script to delete &quot;datetime  message&quot; and a particular patern exists? in short I want my file to this following output.
### original file ###
datetime	message
2011-07-13 13:45:35	Hello World of War Craft
2011-07-13 13:48:43	This is a Test  of text
### output file ###
20110713134535 &#124; Hello World of War Craft
20110713134843 &#124; This is a Test  of text
thanks</description> <content:encoded><![CDATA[<p>I would like to know how i can write a shell script to delete &#8220;datetime  message&#8221; and a particular patern exists? in short I want my file to this following output.</p><p>### original file ###<br
/> datetime	message<br
/> 2011-07-13 13:45:35	Hello World of War Craft<br
/> 2011-07-13 13:48:43	This is a Test  of text</p><p>### output file ###<br
/> 20110713134535 | Hello World of War Craft<br
/> 20110713134843 | This is a Test  of text</p><p>thanks</p> ]]></content:encoded> </item> <item><title>By: Simplesol</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-59396</link> <dc:creator>Simplesol</dc:creator> <pubDate>Fri, 13 May 2011 18:59:37 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-59396</guid> <description>All you are trying to do is this:
grep -v &quot;^$&quot; * &#124; wc -l</description> <content:encoded><![CDATA[<p>All you are trying to do is this:</p><p>grep -v &#8220;^$&#8221; * | wc -l</p> ]]></content:encoded> </item> <item><title>By: Angwe</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-49043</link> <dc:creator>Angwe</dc:creator> <pubDate>Thu, 26 Aug 2010 14:44:53 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-49043</guid> <description>This is old, but in case no-one told you:
\w is the special regular expression for whitespace. Both the sed and grep matches should be changed to:
/^\w*$/
-Angwe</description> <content:encoded><![CDATA[<p>This is old, but in case no-one told you:</p><p>\w is the special regular expression for whitespace. Both the sed and grep matches should be changed to:</p><p>/^\w*$/</p><p>-Angwe</p> ]]></content:encoded> </item> <item><title>By: sobi3ch</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-46904</link> <dc:creator>sobi3ch</dc:creator> <pubDate>Fri, 16 Apr 2010 07:16:05 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-46904</guid> <description>how count all lines in all files in current dir and omit empty lines with wc, grep, cut and bc commands
echo `wc -l * &#124; grep total &#124; cut -f2 -d&#039; &#039;` - `grep -in &quot;^$&quot; * &#124; wc -l ` &#124; bc</description> <content:encoded><![CDATA[<p>how count all lines in all files in current dir and omit empty lines with wc, grep, cut and bc commands</p><p>echo `wc -l * | grep total | cut -f2 -d&#8217; &#8216;` &#8211; `grep -in &#8220;^$&#8221; * | wc -l ` | bc</p> ]]></content:encoded> </item> <item><title>By: ezz</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-44444</link> <dc:creator>ezz</dc:creator> <pubDate>Wed, 04 Nov 2009 16:48:38 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-44444</guid> <description>This is quite helpful. Thanks!!</description> <content:encoded><![CDATA[<p>This is quite helpful. Thanks!!</p> ]]></content:encoded> </item> <item><title>By: Niju N B</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42502</link> <dc:creator>Niju N B</dc:creator> <pubDate>Mon, 13 Jul 2009 11:52:42 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42502</guid> <description>Hi,
var_a=$(grep -R &quot;SP1_125&quot; filename)</description> <content:encoded><![CDATA[<p>Hi,<br
/> var_a=$(grep -R &#8220;SP1_125&#8243; filename)</p> ]]></content:encoded> </item> <item><title>By: Niju N B</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42501</link> <dc:creator>Niju N B</dc:creator> <pubDate>Mon, 13 Jul 2009 11:49:46 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42501</guid> <description>var_a = $(grep -R &quot;SP1_125&quot; &lt;filename&gt;)</description> <content:encoded><![CDATA[<p>var_a = $(grep -R &#8220;SP1_125&#8243; &lt;filename&gt;)</p> ]]></content:encoded> </item> <item><title>By: Niju N B</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42500</link> <dc:creator>Niju N B</dc:creator> <pubDate>Mon, 13 Jul 2009 11:47:30 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42500</guid> <description>Hi,
Using the command
grep -R &quot;SP1_125&quot;
you can get the lines with SP1_125.
if you want to assign to a variable then use
var_a=$(grep -R &quot;SP1_125&quot;   )
where  is the name of file</description> <content:encoded><![CDATA[<p>Hi,</p><p>Using the command<br
/> grep -R &#8220;SP1_125&#8243;<br
/> you can get the lines with SP1_125.<br
/> if you want to assign to a variable then use<br
/> var_a=$(grep -R &#8220;SP1_125&#8243;   )</p><p>where  is the name of file</p> ]]></content:encoded> </item> <item><title>By: Renz</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42109</link> <dc:creator>Renz</dc:creator> <pubDate>Thu, 18 Jun 2009 06:22:04 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-42109</guid> <description>what if there&#039;s spaces and tab in the line I want to delete?
thanks,
Renz</description> <content:encoded><![CDATA[<p>what if there&#8217;s spaces and tab in the line I want to delete?</p><p>thanks,<br
/> Renz</p> ]]></content:encoded> </item> <item><title>By: REDDY SIVA SARAN</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-41210</link> <dc:creator>REDDY SIVA SARAN</dc:creator> <pubDate>Wed, 15 Apr 2009 10:46:17 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-41210</guid> <description>Hi,
I am Siva Saran
I am new to linux environment
can any on tell plz that how to get a particular line from a file using linux commands
For example say that inputfile has lines as follows
total 0
d [RWCEAFMS] MRohit                            512 Apr 15 03:15 3.1_SP1_Beta1_127
d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.1_SP1_125                     d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.1_SP1_259
d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.0_SP4_IR3_62
Now I want the line which is having SP1_125 ie., line number 3 and store it in an variable
plz can any tell the answer plz
can u mail to {snip_no_email_ids}</description> <content:encoded><![CDATA[<p>Hi,<br
/> I am Siva Saran<br
/> I am new to linux environment<br
/> can any on tell plz that how to get a particular line from a file using linux commands<br
/> For example say that inputfile has lines as follows<br
/> total 0<br
/> d [RWCEAFMS] MRohit                            512 Apr 15 03:15 3.1_SP1_Beta1_127<br
/> d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.1_SP1_125                     d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.1_SP1_259<br
/> d [RWCEAFMS] MRohit                            512 Apr 14 03:26 3.0_SP4_IR3_62</p><p>Now I want the line which is having SP1_125 ie., line number 3 and store it in an variable<br
/> plz can any tell the answer plz<br
/> can u mail to {snip_no_email_ids}</p> ]]></content:encoded> </item> <item><title>By: Dennis</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-40031</link> <dc:creator>Dennis</dc:creator> <pubDate>Wed, 28 Jan 2009 14:34:44 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-40031</guid> <description>Actually, grep&#039;s -v (--invert-match) option inverts the sense of matching, thus selecting non-matching lines.
Therefore, only when combining it with the pattern &#039;^$&#039; does it mean to select everything except blank lines.
Just thought the way you explained it might be confusing for beginners. When I was new to shell and Linux, most of the guides or forums were useless because they all assumed that the person that needs help has some high understanding of shell or Linux already, and thus they use a lot of terms that person would have never heard of before or they don&#039;t explain anything. Once you have a basic understanding, the learning comes easier, but in the beginning, the learning curve has an almost horizontal slope.</description> <content:encoded><![CDATA[<p>Actually, grep&#8217;s -v (&#8211;invert-match) option inverts the sense of matching, thus selecting non-matching lines.<br
/> Therefore, only when combining it with the pattern &#8216;^$&#8217; does it mean to select everything except blank lines.<br
/> Just thought the way you explained it might be confusing for beginners. When I was new to shell and Linux, most of the guides or forums were useless because they all assumed that the person that needs help has some high understanding of shell or Linux already, and thus they use a lot of terms that person would have never heard of before or they don&#8217;t explain anything. Once you have a basic understanding, the learning comes easier, but in the beginning, the learning curve has an almost horizontal slope.</p> ]]></content:encoded> </item> <item><title>By: Prashant Deshani</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-39315</link> <dc:creator>Prashant Deshani</dc:creator> <pubDate>Wed, 26 Nov 2008 13:19:33 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-39315</guid> <description>Hi,
I tried to use the command sed given above to remove blank line from my file.
The file looks good except one strange behaviour:
&quot;Always&quot; the last line of the file is removed..for example:
test.p is the file and following are the contents of the file:
BEFORE RUNNING THE SED COMMAND:
&quot;this is test 1.
this is test 2.
this is test 3.&quot;
AFTER RUNNING THE SED COMMAND:
&quot;this is test 1.
this is test 2.&quot;
As you can see the last line (&quot;this is test 3.&quot;) is removed after running the command.
If I put the blank line at the end it removes the blank line i.e.
&quot;this is test 1.
this is test 2.
this is test 3.
&quot;
becomes.......
&quot;this is test 1.
this is test 2.
this is test 3.&quot;
Do let me know what I should do in this case?
Waiting for your prompt reply...!
Thanks and Best Regards,
Prashant Deshani</description> <content:encoded><![CDATA[<p>Hi,</p><p>I tried to use the command sed given above to remove blank line from my file.</p><p>The file looks good except one strange behaviour:<br
/> &#8220;Always&#8221; the last line of the file is removed..for example:<br
/> test.p is the file and following are the contents of the file:</p><p>BEFORE RUNNING THE SED COMMAND:<br
/> &#8220;this is test 1.</p><p>this is test 2.</p><p>this is test 3.&#8221;</p><p>AFTER RUNNING THE SED COMMAND:<br
/> &#8220;this is test 1.<br
/> this is test 2.&#8221;</p><p>As you can see the last line (&#8220;this is test 3.&#8221;) is removed after running the command.</p><p>If I put the blank line at the end it removes the blank line i.e.<br
/> &#8220;this is test 1.</p><p>this is test 2.</p><p>this is test 3.</p><p>&#8221;</p><p>becomes&#8230;&#8230;.<br
/> &#8220;this is test 1.<br
/> this is test 2.<br
/> this is test 3.&#8221;</p><p>Do let me know what I should do in this case?</p><p>Waiting for your prompt reply&#8230;!</p><p>Thanks and Best Regards,<br
/> Prashant Deshani</p> ]]></content:encoded> </item> <item><title>By: Rick</title><link>http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-39070</link> <dc:creator>Rick</dc:creator> <pubDate>Tue, 28 Oct 2008 17:37:58 +0000</pubDate> <guid
isPermaLink="false">http://www.cyberciti.biz/faq/howto-linux-unix-command-remove-all-blank-lines/#comment-39070</guid> <description>When writing to the same file, or a different file and using the redirect &gt; the file ends up blank.
This removes blank lines from input.txt
sed &#039;/^$/d&#039; -i input.txt</description> <content:encoded><![CDATA[<p>When writing to the same file, or a different file and using the redirect &gt; the file ends up blank.</p><p>This removes blank lines from input.txt</p><p>sed &#8216;/^$/d&#8217; -i input.txt</p> ]]></content:encoded> </item> </channel> </rss>
