linux - How to insert a column with serial number in shell? -


i have file 4 colums.

ifile.txt 2 3 4 2 2 3 4 1 4 3 4 3 4 5 3 5 . . . . 

i need insert column serial number like:

ofile.txt 1 2 3 4 2 2 2 3 4 1 3 4 3 4 3 4 4 5 3 5 5 . . . . . . . . . 

i trying using awk , unsuccessful

awk '{print i, $1, $2, $3, $4}' ifile.txt > ofile.txt 

you can use built-in nr 1-based record counter.

awk '{print nr, $1, $2, $3, $4}' ifile.txt > ofile.txt 

the general-purpose form is:

awk '{print nr, $0}' 

that print out entire record (prefixed sequence number), regardless of how many fields there are.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -