# Replacing a specific column of a text file with another column

**URL:** <https://community.unix.com/t/replacing-a-specific-column-of-a-text-file-with-another-column/295457>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [September 16, 2011, 5:20pm UTC](https://community.unix.com/t/replacing-a-specific-column-of-a-text-file-with-another-column/295457 "2011-09-16T17:20:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evelibertine](https://community.unix.com/letter_avatar/evelibertine/32/5_5575768a8748004e209b776fc1b2916d.png) [@evelibertine](https://community.unix.com/u/evelibertine)\
**Post date:** [September 16, 2011, 5:20pm UTC](https://community.unix.com/t/replacing-a-specific-column-of-a-text-file-with-another-column/295457/1 "2011-09-16T17:20:04Z")

</div>

Hi,  
I have a text file in the following format:

Code:  
13412 NA06985 0 0 2 46.6432798439 4 4 4 4  
13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4  
13412 NA06993 0 0 1 45.8022601455 4 4 2 4  
13401 NA06994 0 0 1 48.780669145 4 4 4 4  
13401 NA07000 0 0 2 47.7312017846 2 4 4 4  
13402 NA07019 NA07022 NA07056 2 41.7389244255 4 4 4 4  
13402 NA07022 0 0 1 54.1498530714 4 4 4 4  
13401 NA07029 NA06994 NA07000 1 X 2 4 4 4  
13411 NA07034 0 0 1 41.709838673 4 4 2 4  
13411 NA07048 NA07034 NA07055 1 41.4599808018 4 4 4 4

I want to replace column 6 with a different column (The new column is in a file called column.txt) How do I go about doing that? Thanks!

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [September 16, 2011, 6:01pm UTC](https://community.unix.com/t/replacing-a-specific-column-of-a-text-file-with-another-column/295457/2 "2011-09-16T18:01:17Z")

</div>

Try:

```nohighlight
awk 'NR==FNR{a[NR]=$0;next}{$6=a[FNR]}1' column.txt file

```

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [September 17, 2011, 4:18am UTC](https://community.unix.com/t/replacing-a-specific-column-of-a-text-file-with-another-column/295457/3 "2011-09-17T04:18:55Z")

</div>

Alternatively:

```nohighlight
awk 'getline $6<f' f=column.txt file

```
