LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   search for blank lines with awk (https://www.linuxquestions.org/questions/linux-newbie-8/search-for-blank-lines-with-awk-766248/)

_vibeke_ 11-02-2009 10:17 AM

search for blank lines with awk
 
Hi!!

I'm new at this :(
I'm trying to make a program to search for each blank line in a text archive, where blocks are separated by this blank lines. I want to write the number of the line in a new file "numblank.txt"

I have this, but I think I have a problem with the "blank line" simbol.
Can anyone help me please?

awk '{if ($1 == /^$/) print NR }' $file1 >! numblank.tmp


where file1 is given as:

text
text

text
text
text
text

text
text (blocks are uneven)


Thank you!!!

Tinkster 11-02-2009 10:26 AM

Hi,

welcome to LQ!

What do you consider to be "the blank line symbol"? In most shells
I'm aware of an exclamation mark is a history expansion command;
what you're trying to achieve should work fine if you omit the '!'.



Cheers,
Tink

_vibeke_ 11-03-2009 07:28 AM

Quote:

Originally Posted by Tinkster (Post 3741362)

What do you consider to be "the blank line symbol"?

Hi Tinker,
I meant the /^$/ by "blank symbol".

I'll try without the exclamation symbol.... and, it doesn't work :(
But I found another way to write the script, thanks anyway :D

ghostdog74 11-03-2009 07:30 AM

if you want "blank lines" (actually they are newlines), just check for no fields
Code:

$ awk '!NF{print NR}' file
3
6
9


pixellany 11-03-2009 07:57 AM

sed -n '/^$/=' filename >> blankfile

bsat 11-04-2009 01:54 AM

This should also work.
awk '/^$/{print NR}' file > numfiles


All times are GMT -5. The time now is 10:49 AM.