![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 06:19 AM |
| generate random number in perl | zx1106 | Shell Programming and Scripting | 2 | 03-17-2008 08:13 PM |
| generate random number in korn shell | frustrated1 | Shell Programming and Scripting | 2 | 12-31-2005 03:49 AM |
| How to generate a random number? | MacMonster | High Level Programming | 2 | 10-15-2001 09:35 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi.
I have a script wich reads 1 file and generates 4. If the original file has 10 lines the the sum of the 4 generated files must have the 10 original lines. So far this works. Now what I need is to numerate the lines wtithin each generated file. I tried with NR but it prints the line number of the original file, and I need each file to start from 1. Example: Original: 1,2,3,4,5,6,7,8,9 using NR Gen_1: 2,5,8,9 Gen_2: 1,3,4,6,7 and what I need is: Original: 1,2,3,4,5,6,7,8,9 Gen_1: 1,2,3,4 Gen_2: 1,2,3,4,5 any ideas? thanks in advance. |
| Forum Sponsor | ||
|
|
|
|||
|
After you have created your 4 files, you could do something like
awk "{print NR,$0}" file1 > file1_with_line_numbers awk "{print NR,$0}" file2 > file2_with_line_numbers awk "{print NR,$0}" file3 > file3_with_line_numbers awk "{print NR,$0}" file4 > file5_with_line_numbers |
|
|||
|
Yes, that could work.
However the whole idea of the script is to read the source file and write the generated files only once. Thanks for the idea, but given the size of the files to process, the line number should be writen with the rest of the line, so the file only gets processed once. |
|||
| Google The UNIX and Linux Forums |