LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 10: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, 10:26 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 07: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, 07: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 07:59 AM.
 
Old 11-03-2009, 07:57 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

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

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


Reply



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-07-2008 11:56 PM
awk print correct lines when certain columns are blank schneidz Programming 11 04-04-2008 04:06 PM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
awk text that is on several lines homey Programming 2 10-31-2004 09:27 AM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:35 PM.

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
Open Source Consulting | Domain Registration