LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-02-2009, 11:17 AM   #1
_vibeke_
LQ Newbie
 
Registered: Nov 2009
Location: Santiago, Chile
Posts: 2

Rep: Reputation: 0
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!!!
 
Old 11-02-2009, 11:26 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 11-03-2009, 08:28 AM   #3
_vibeke_
LQ Newbie
 
Registered: Nov 2009
Location: Santiago, Chile
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post

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
 
Old 11-03-2009, 08:30 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
if you want "blank lines" (actually they are newlines), just check for no fields
Code:
$ awk '!NF{print NR}' file
3
6
9

Last edited by ghostdog74; 11-03-2009 at 08:59 AM.
 
Old 11-03-2009, 08:57 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
sed -n '/^$/=' filename >> blankfile
 
Old 11-04-2009, 02:54 AM   #6
bsat
Member
 
Registered: Feb 2009
Posts: 347

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Awk Question to search specific strings grouped by blank lines rk4k Programming 6 07-08-2008 12:56 AM
awk print correct lines when certain columns are blank schneidz Programming 11 04-04-2008 05:06 PM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 10:19 AM
awk text that is on several lines homey Programming 2 10-31-2004 10:27 AM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 05:49 PM


All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration