The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-21-2007 02:34 AM
generating random numbers with hamming distance 4 hack_tom Shell Programming and Scripting 2 04-29-2007 01:27 AM
add line numbers esham Shell Programming and Scripting 4 03-07-2005 10:46 AM
Printing line numbers MizzGail UNIX for Dummies Questions & Answers 2 07-25-2002 04:18 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-28-2008
sam4now sam4now is offline
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
  #2 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.)
  #3 (permalink)  
Old 04-28-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
I kjnow the cat -n works but puting the ) after each number line is complicated bit
  #4 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 05:20 PM.. Reason: awk too
  #5 (permalink)  
Old 04-28-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
sed = a | sed 'N; s/^/     /; s/ *\(.\{6,\}\)\n/\1)  /'
sed1line
  #6 (permalink)  
Old 04-28-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
nl -s\)\  -w1 file
  #7 (permalink)  
Old 04-28-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
any other way without the sed and awk plssss
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 On




All times are GMT -4. The time now is 06:30 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0