Auto generate Line Numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto generate Line Numbers
# 1  
Old 03-18-2013
Auto generate Line Numbers

How do I generate line numbers in Vi?

I have this:


Code:
,'04-90020-039N','61423','2GDV00039-0002', SYSDATE);
,'04-90020-040D','61423','2GDV00046-0001', SYSDATE);
,'04-90020-041N','61423','2GDV00038-0002', SYSDATE);
,'04-90020-043D','61423','2GDV00047-0001', SYSDATE);
,'04-90020-044D','73168','2GDV00071-0002', SYSDATE);
,'0453-941-110','1DJ82','0453-941-110', SYSDATE);
,'0456-931-110-01','1DJ82','0456-931-110-01', SYSDATE);
,'0456-933-111','1DJ82','0456-933-111', SYSDATE);
,'0N687022-509','11447','2ZKH85070-0005', SYSDATE);
,'1000538','83330','1000538', SYSDATE);

And I want to put a line number in front of the line. This goes on for 23k+ lines.

Code:
1,'04-90020-039N','61423','2GDV00039-0002', SYSDATE);
2,'04-90020-040D','61423','2GDV00046-0001', SYSDATE);
3,'04-90020-041N','61423','2GDV00038-0002', SYSDATE);
4,'04-90020-043D','61423','2GDV00047-0001', SYSDATE);
5,'04-90020-044D','73168','2GDV00071-0002', SYSDATE);
6,'0453-941-110','1DJ82','0453-941-110', SYSDATE);
7,'0456-931-110-01','1DJ82','0456-931-110-01', SYSDATE);
8,'0456-933-111','1DJ82','0456-933-111', SYSDATE);
9,'0N687022-509','11447','2ZKH85070-0005', SYSDATE);
10,'1000538','83330','1000538', SYSDATE);


thanks.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-18-2013 at 06:49 PM.. Reason: code tags, please!
# 2  
Old 03-18-2013
try (if your vi version supports setting regular expressions for replacement) for updating lines with line #:
Code:
:1,$s/^/\=" " . line(".")/


Last edited by rdrtx1; 03-18-2013 at 05:53 PM..
# 3  
Old 03-18-2013
If the vi does not work, this will work:
Code:
nl -s "" infile | sed "s/^ *//"

Or, you can do same in vim, maybe other vi versions:
Code:
:1,$ !nl -s "" | sed "s/^ *//"

Or, vi has the :set nu command in case that is what you are looking for.
# 4  
Old 03-18-2013
Code:
:set nu

Smilie

--
Outside vi:
Code:
awk '{print NR $0}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

2. Shell Programming and Scripting

Generate random numbers in script

i want to generate a random number through a script, and even if anyone reads the script, they wont be able to figure out what the random number is. only the person who setup the script would know it. something like this could work: random the full thread is here: ... (13 Replies)
Discussion started by: SkySmart
13 Replies

3. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

4. Shell Programming and Scripting

Generate numbers 000 to 999

I have tried to make this script to generate: 000 001 002 ... 997 998 999 i=0 while do if then echo "00"$i else if && then echo "0"$i (5 Replies)
Discussion started by: locoroco
5 Replies

5. Shell Programming and Scripting

How to generate 10.000 unique numbers?

hello, does anybody can give me a hint on how to generate a lot of numbers which are not identically via scripting etc? (7 Replies)
Discussion started by: xrays
7 Replies

6. Shell Programming and Scripting

How to Auto Generate pg_hba.conf file at Startup

Hi there, I'll start by letting you you know my current shell programming and scripting is very week (and thats a euphemistic description). I'm really just wanting someone to make a suggestion to get me rolling in the right direction though absolutely any help is of course welcome. Set Up -... (0 Replies)
Discussion started by: lukusc
0 Replies

7. UNIX for Dummies Questions & Answers

auto generate ID

Using 'awk' i want to generate new ID..which should be increment of maximum number given as UID.. eg..in /etc/passwd..3rd field is UID..and we just want next user ID for this file..keep in mind that file is not sorted..so last line in the file may not display last UID..means UIDs in file are... (1 Reply)
Discussion started by: aadi_uni
1 Replies

8. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

9. Shell Programming and Scripting

How to generate a series of numbers

Hi All, I have a requirement where in I have an input as follows:- input=1-4,6,8-10,12-15 I need to explode this range into an output file as follows:- 1 2 3 4 6 8 9 10 12 13 14 15 My input may vary like 1,5-9,11-13,15-17....... (3 Replies)
Discussion started by: rony_daniel
3 Replies

10. Shell Programming and Scripting

generate level numbers

Hi... I have a sequence of jobs and its predecessors.. Input Job_Name Predecessor A NULL B1 A B2 A B3 B1 C B3 C B2 So based on these i have to generate the level Number What i mean is Let A be level 1 for B1 to happen it should have done A so B1 level is A+1 = 1+1 = 2 (12 Replies)
Discussion started by: pbsrinivas
12 Replies
Login or Register to Ask a Question