Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google site



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2006
Registered User
 

Join Date: Sep 2006
Posts: 18
Question numbering blanks

hello i'm trying to figure out how to number a blank line. For instance this :
sed '/./=' file | sed '/./N; s/\n/ /'

gives me
1 aaaa
2 bbbbbb

4 cccccc
5 ffkkkfff
6 ffsdfdfs

I would like something like this:
1 aaaaa
2
3 bbbbbb
4
5 cccccc

And so on... What would i have to do?
I appreciate any help. Thanks.
Sponsored Links
  #2 (permalink)  
Old 11-22-2006
blowtorch's Avatar
AFK
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,351
Do you mind using awk?

Code:
awk 'BEGIN {x=1;} {print x,$0;x++}' filename

  #3 (permalink)  
Old 11-22-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,431
Or...
Code:
pr -t -n filename

  #4 (permalink)  
Old 11-22-2006
Technorati Master
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 3,006
Quote:
Originally Posted by blowtorch
Do you mind using awk?

Code:
awk 'BEGIN {x=1;} {print x,$0;x++}' filename

Blowtorch,
Is incremental really needed ?

what about this,


Code:
awk '{ printf "%d %s\n", NR, $0 }' filename

1 aaaa
2 eeee
3
4 bbbb
5
6 cccc
  #5 (permalink)  
Old 11-22-2006
blowtorch's Avatar
AFK
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,351
Good point... was probably in dummy mode when I wrote that.
  #6 (permalink)  
Old 11-22-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,106
using sed

Code:
sed = myfile | sed 'N;s/\n/\t/'

....numbers all the lines in a file.
  #7 (permalink)  
Old 11-22-2006
Registered User
 

Join Date: Sep 2006
Posts: 18
Thanks everyone.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Blanks vs: Nulls ebock High Level Programming 1 02-12-2008 05:16 PM
blanks in file name LisaS Shell Programming and Scripting 1 10-06-2005 09:20 PM
blanks in an awk comand collie Shell Programming and Scripting 1 08-25-2004 01:09 PM
Numbering merlin Shell Programming and Scripting 3 06-07-2002 01:23 AM
Numbering! biglemon UNIX for Dummies Questions & Answers 9 01-21-2002 03:58 AM



All times are GMT -4. The time now is 07:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0