![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to uniq third field in a file | babycakes | UNIX for Dummies Questions & Answers | 1 | 02-01-2008 12:52 AM |
| compare two col from 2 files, and output uniq from file 1 | pp56825 | Shell Programming and Scripting | 2 | 01-10-2008 08:10 AM |
| Inserting argument into top of a file | Dev06 | UNIX for Dummies Questions & Answers | 7 | 10-05-2006 01:16 PM |
| Inserting a new column in a file | rosh0623 | UNIX for Advanced & Expert Users | 4 | 08-01-2006 08:15 AM |
| Reading special characters while converting sequential file to line sequential | Rajeshsu | High Level Programming | 2 | 07-10-2006 11:38 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
inserting uniq sequential numbers at the start of the file
Hi Unix gurus,
I have a file. I need to insert sequential number at the starting of the file. Fields are delimited by "|". I know the starting number. Example: File is as follows |123|4test|test |121|2test|test |x12|1test|test |vd123|5test|test starting number is : 120 output must be : 120|123|4test|test 121|121|2test|test 122|x12|1test|test 123|vd123|5test|test Advance thanks for helping. Jingi |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
awk 'BEGIN{n=120}{printf("%s%s\n",n++,$0)}' infile > outfile
Cheers ZB |
|
#3
|
|||
|
|||
|
Quote:
Can 120 be a varaible? I mean variable=12 awk 'BEGIN{n=$variable}{printf("%s%s\n",n++,$0)}' infile > outfile ?? The aboe statement doesn't work if it is variable..what is the work around? |
|
#4
|
||||
|
||||
|
Quote:
Code:
nawk -v n=120 '{printf("%s%s\n",n++,$0)}' infile > outfile
|
|
#5
|
|||
|
|||
|
What if the file has "tab" [\t] as a delimter? what should i change in the nawk?
Please help Last edited by jingi1234; 11-17-2005 at 09:22 AM. |
|
#6
|
|||
|
|||
|
Gurus,
Please help |
|
#7
|
||||
|
||||
|
Quote:
|
||||
| Google The UNIX and Linux Forums |