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
find 2 line numbers, grab text in between Da_Duck Shell Programming and Scripting 11 09-26-2006 09:51 AM
Print only certain lines from a text file CamTu Shell Programming and Scripting 1 06-01-2005 08:47 AM
Search for text and print the next line alijassim Shell Programming and Scripting 2 08-17-2004 03:08 AM
PERL:print 32 variables into a text file perleo Shell Programming and Scripting 2 04-25-2003 03:23 AM
How to print a text file in landscape yxiao UNIX for Dummies Questions & Answers 5 06-20-2002 03:21 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-12-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
how to print out line numbers of a text file?

i have this text file name test.txt which contain :
aaaaa bbb
iiiiiiiiiiiii ccf
ddaaa ddd

and i need a script that can print out the line numbers using a while loop..
so when the script is run..it will have this:
1
2
3

any ideas? thanks guys
Reply With Quote
Forum Sponsor
  #2  
Old 12-12-2005
mona's Avatar
Registered User
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
I think the below sed command will help you

sed -n '=' datafile
Reply With Quote
  #3  
Old 12-12-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
thanks again for great help! solve part of my problem already..thanks...
Reply With Quote
  #4  
Old 12-12-2005
encrypted's Avatar
Registered User
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 218
cat -n <filename>|awk '{print $1}'

should help
Reply With Quote
  #5  
Old 12-12-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
thanks very much!
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 05:46 AM.


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