The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help capturing end of line numbers icalderus SUN Solaris 3 09-20-2007 11:34 PM
generating random numbers with hamming distance 4 hack_tom Shell Programming and Scripting 2 04-28-2007 10:27 PM
add line numbers esham Shell Programming and Scripting 4 03-07-2005 07:46 AM
Printing line numbers MizzGail UNIX for Dummies Questions & Answers 2 07-25-2002 01:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-28-2008
Registered User
 

Join Date: Apr 2008
Posts: 23
generating line numbers

hello All

Do anybody know how to generat number line
that is puting the number of lines at the begining of a new line, with d bracket by the side
say
1)
2)
3)

any help would be nice
Reply With Quote
Forum Sponsor
  #2  
Old 04-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The "Similar Threads" at the bottom of this page would be a good place to start. (Too bad the forums don't display that until you have posted your question.)
Reply With Quote
  #3  
Old 04-28-2008
Registered User
 

Join Date: Apr 2008
Posts: 23
I kjnow the cat -n works but puting the ) after each number line is complicated bit
Reply With Quote
  #4  
Old 04-28-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
cat -n "$file" | sed -e 's/^ *[1-9][0-9]*/&)/'
The regular expression matches start of line, zero or more spaces, and a nonzero positive integer, and sed replaces any match with whatever matched (& is the "magic" character which does this) and a right parenthesis.

Actually this is probably easier in awk.

Code:
awk '{ print NR ") " $0 }' "$file"
NR is the current line number and $0 is the input line.

Last edited by era; 04-28-2008 at 02:20 PM. Reason: awk too
Reply With Quote
  #5  
Old 04-28-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,019
Code:
sed = a | sed 'N; s/^/     /; s/ *\(.\{6,\}\)\n/\1)  /'
sed1line
Reply With Quote
  #6  
Old 04-28-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,924
Code:
nl -s\)\  -w1 file
Reply With Quote
  #7  
Old 04-28-2008
Registered User
 

Join Date: Apr 2008
Posts: 23
any other way without the sed and awk plssss
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0