How to insert new column with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert new column with awk?
# 1  
Old 04-24-2017
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:

Code:
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 format:
Code:
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 00 00 E F 1 ;
A B C D 00 00 E F 1 ;

Please advise.

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 04-24-2017 at 04:23 PM.. Reason: Added CODE tags.
# 2  
Old 04-24-2017
Any attempts / ideas / thoughts from your side?
# 3  
Old 04-24-2017
Quote:
Originally Posted by RudiC
Any attempts / ideas / thoughts from your side?
I tried this

Code:
awk '{if (NR>=3) $4=$4" ""00"" ""00"; print }' file > file-2

Can you propose better solution?

Last edited by Scrutinizer; 04-24-2017 at 06:25 PM.. Reason: code tags
# 4  
Old 04-24-2017
not sure if you really meant to change the line and output it twice (if not, remove the print statement), but.......
Code:
awk 'FNR>3 {$4=$4 OFS "00" OFS "00";print}1' myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 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 a column inside a dataset with awk?

Hello folks I have a file called fill1.txt which contains: 1 2 2 1 1 2 1 2 my other file is called fill2.txt which contains: 1 2 1 2 2 2 1 2 1 2 1 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 1 2 2 1 Now, I am looking for a awk command which could insert fill1.txt between... (1 Reply)
Discussion started by: sajmar
1 Replies

4. 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

5. Shell Programming and Scripting

Reorder and insert column using awk

Hi friends, I am beginner in shell scripting. I am trying to modify (Reorder and insert column) a BIG .txt file using awk to create a .bim file. My start file has 25 columns But I need to make a new file with only 5 columns from the start file and insert a new column in position 3 with value... (5 Replies)
Discussion started by: smitra
5 Replies

6. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: kush
2 Replies

7. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
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. 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