insert a column into file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers insert a column into file
# 1  
Old 03-01-2012
insert a column into file

hi everybody!
Could u show me how to do following:
I have files (in total 22) .txt that contain one column of values (the total number of values varies from file to file from 40.0000 to 10.000). For example:

742429
758311
995669
1008567
1011278
1011521
1020428
1021403
...
And I need to insert a column (it should be the first one in new file) which will basically contain counts of the values in the second column starting from zero. For example:


0 742429
1 758311
2 995669
3 1008567
4 1011278
5 1011521
6 1020428
7 1021403

Thank u for ur time and sharing knowledge!
kush
# 2  
Old 03-01-2012
Code:
awk '{print NR-1,$0}' file

# 3  
Old 03-01-2012
thank u a lot, bartus!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. UNIX for Advanced & Expert Users

Insert a column in the beginning

Hi, I have been trying to see how i can insert a column in the beginning to my html table This is how it looks Name Age Sid 32 John 33 Mary 34 I want to insert a column Job before Name column, so it looks like Job Name Age IT Sid 32 Doctor... (3 Replies)
Discussion started by: sidnow
3 Replies

3. Shell Programming and Scripting

How to insert new column with awk?

Hello guys, I'm new to shell programming, I would like to insert two new columns in a space separated file having this format using awk, starting from the third row: A B C D E F 1 ; A B C D E F 1 ; A B C D E F 1 ; A B C D E F 1 ; Basically, the resulting file should have the following... (3 Replies)
Discussion started by: transat
3 Replies

4. Shell Programming and Scripting

Insert value of column based on file name matching

At the top of the XYZ file, I need to insert the ABC data value of column 2 only when ABC column 1 matches the prefix XYZ file name (not the ".txt"). Is there an awk solution for this? ABC Data 0101 0.54 0102 0.48 0103 1.63 XYZ File Name 0101.txt 0102.txt 0103.txt ... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

5. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

6. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

7. Shell Programming and Scripting

Insert first line of a file to first column of remaining files

I want to extraxt data from a html table the html file is downloaded from UG / PG Univ - Exam.Results April/May 2008 After processing the html file using sed i got the output like this 11305106082,RANJANI R, CS1251,20,69,P CS1302,20,45,P EC1006,20,52,P EC1351,20,53,P... (5 Replies)
Discussion started by: a_artha
5 Replies

8. Shell Programming and Scripting

insert text into column

Hello! I have a text file containing some text : : : bla other text : : : bla any text : : : bla containing 3 columns separated by the ':' sign. Now i want to insert 'this' in the 2nd line after the 2nd column-deliminiter (i.e. into 3rd column), like some text : : : bla other text :... (1 Reply)
Discussion started by: knoxo
1 Replies

9. Shell Programming and Scripting

insert a variable in the last column of a file

i want to insert a variable in the last column of a file, the columns are separated by "|". I want to insert the variable in everyline of the file . (7 Replies)
Discussion started by: dineshr85
7 Replies

10. UNIX for Dummies Questions & Answers

How to insert tab at specified column.HELP

I have input like: 1234567890 cut -c1-3,6-7,9-10 input > output Now I got 1236790. I want to insert space between each cut. So the output like: 123 67 90 Can anybody help? Thanks. (7 Replies)
Discussion started by: sslr
7 Replies
Login or Register to Ask a Question