简体   繁体   中英

How to add column numbers to each column in a large text file

I would like to add column numbers to 128 columns in a text file Eg

My file

 12 13 14 15
 20 21 23 14
 34 56 67 89

Required output

  1:12     2:13    3:14     4:15
  1: 20    2:21    3: 23    4:14
  1: 34    2:56    3:67     4:89

Can this be done using awk / python I tried paste command for joining two files : one with the values other file with column numbers, manually typed. Since the file size is very large manual typing didnt work. As of my knowledge I could find answers for adding only one column to the end of a text file. Thanks for the suggestions

awk to the rescue!

$ awk '{for(i=1;i<=NF;i++) $i=i":"$i}1' file

should do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM