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
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 05:29 AM
Edit number of lines in a file to single line chiru_h Shell Programming and Scripting 3 04-01-2008 08:27 PM
SED: Update Last Line with Number Lines in File bmkux Shell Programming and Scripting 3 01-07-2008 06:16 PM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-20-2007 09:29 PM
display lines after a particular line number rajashekar.y UNIX for Dummies Questions & Answers 6 01-02-2007 11:53 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Jul 2006
Posts: 68
Appending line number to each line and getting total number of lines

Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me.
I have a file say:
abc
def
ccc
ddd
ffff

The output should be:
Instance1=abc
Instance2=def
Instance3=ccc
Instance4=ddd
Instance5=ffff

Total number of Instances=5

Thanks,
Chiru
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 542
Code:
awk '{print "Instance"NR"="$0} END {print "Total number of Instances = "NR}' file
Reply With Quote
  #3 (permalink)  
Old 03-25-2008
Registered User
 

Join Date: Jul 2006
Posts: 68
Thanks Shamrock, that works correctly..

-Chiru
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06: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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0