How to insert a column inside a dataset with awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to insert a column inside a dataset with awk?
# 1  
Old 01-28-2015
How to insert a column inside a dataset with awk?

Hello folks
I have a file called fill1.txt which contains:
Code:
1 2 
2 1
1 2
1 2

my other file is called fill2.txt which contains:
Code:
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 column 6-7 in fill2.txt. If anyone could give me any solution for this particular question, I will be appreciated.

Regards
Sajmar

Last edited by Scrutinizer; 01-28-2015 at 04:59 PM.. Reason: code tags
# 2  
Old 01-28-2015
Try:
Code:
awk '(getline p<f)>0{$7=p OFS $7}1' f=fill1.txt fill2.txt

or
Code:
awk 'NR==FNR{A[FNR]=$0; next} {$7=A[FNR] OFS $7}1' fill1.txt fill2.txt

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

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

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

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

6. Solaris

flarecreate for zfs root dataset and ignore multiple dataset

Hi All, I want to write a script to create flar images on multiple servers. In non zfs filesystem I am using -X option to refer a file to exclude mounts on different servers. but on ZFS -X option is not working. I want multiple mounts to be ignore on ZFS base system during flarecreate. I... (0 Replies)
Discussion started by: uxravi
0 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

Normalize a dataset with AWK

Hello everyone, i have to normalize this dataset (with 20.000 rows): 2,4,4,3,2,7,8,2,9,11,7,7,1,8,5,6 4,7,5,5,5,5,9,6,4,8,7,9,2,9,7,10 7,10,8,7,4,8,8,5,10,11,2,8,2,5,5,10 4,9,5,7,4,7,7,13,1,7,6,8,3,8,0,8,8 6,7,8,5,4,7,6,3,7,10,7,9,3,8,3,7,8 in this form:... (1 Reply)
Discussion started by: [raven]
1 Replies

9. Web Development

SQL Select inside Insert

I have following. . . . $userid = 2 . $query = "select username from users where userid = ".$userid.";"; . $username = $line; $data="Some Data Here"; . $query = "insert into logger (username, data) valuse ($username, $data);"; . I would like to not have 2 database calls. (3 Replies)
Discussion started by: Ikon
3 Replies
Login or Register to Ask a Question