If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > inserting numbers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-06, 08:01
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
inserting numbers

I would like to insert "echo" followed by a number, but have the number sequentially increase on each line so that I can track where the computer is through my script. So I can pinpoint possible errors with data or my script.

eg, I want to make

line
line
line
line
line
....

into,

line
echo 1
line
echo 2
line
echo 3
line
echo 4
line
echo 5....

Is this possible using sed?
thanks
Reply With Quote
  #2 (permalink)  
Old 02-06-06, 10:32
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
I don't think you can do that with sed, but you can do it with awk.

Code:
awk '{printf("%s\necho %d\n", $0, ++count)}' file
<edit>
It occurs to me that this might also work
Code:
awk '{printf("%s\necho %d\n", $0, NR)}' file
</edit>



.

Last edited by hyperbole; 02-06-06 at 10:55.
Reply With Quote
  #3 (permalink)  
Old 02-06-06, 10:36
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
double post

Last edited by hyperbole; 02-06-06 at 10:53.
Reply With Quote
  #4 (permalink)  
Old 02-06-06, 13:18
davidcollins001 davidcollins001 is offline
Registered User
 
Join Date: Feb 2006
Posts: 15
Excellent, I just tried it - that is just what I was looking for!

I thought that I was going to only use sed as it is great, but looks like I am going to have to learn awk too

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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