0000000 N a m e A g e S e x a l i
0000020 a s n f l d x s d \n C C 2
0000040 5 M K K a s x Y \n B B
0000060 2 1 F S S a w e N \n S D
0000100 2 1 M S D r t y A \n
0000117
Your output is:
0000000 N a m e A g e S e x a l i
0000020 a s n f l d x s d \n C C
0000040 2 5 M K K a s x Y \n B
0000060 B 2 1 F S S a w e N
0000100 \n S D 2 1 M S D r t y
0000120 A \n
0000123
But the reason I asked "based on column header" because I have more than 70 fields in the file (log.txt is just a sample) and field positions are not fixed. I can identify each field based on the field header(Name age sex etc etc).
I feel I explained my query in a wrong way. Let me explain again:
Input file:
$ cat log.txt
Name Age Sex Lcation nfld alias xsd
CC 25 M XYZ asx KK Y
BB 21 F XAS awe SS N
SD 21 M AQW rty SD A
How can I replace the column with header "Lcation" with the column with header "alias" and delete the alias column?
Required output:
Name Age Sex alias nfld xsd
CC 25 M KK asx Y
BB 21 F SS awe N
SD 21 M SD rty A
I don't want to use field number because my actual file contains more than 70 fields and the field positions are not fixed(the above log.txt is just a sample). Thats why I am looking for a solution which replaces based on column header.
Thanks danmero, but still as I stated I have more than 70 columns, so specifying each and every column name is something difficult for me.
i.e.
Name Age Sex ............ fldx bloodgrp .....
A 23 M .............. Y A+ ......
D 21 F................ N B+ ........
......
.......
I wanted to replace a column whose header is "Sex" with the column with header "fldx". The field number of both the columns can be dynamic. So I want to replace them based on their column header name.
so that the output will look something like this
Name Age fldx ................. bloodgrp .......
A 23 Y .................. A+...............
B 21 N ................... B+..............
...............
.............
so the output will not be having the "Sex" column (will be replaced by "fldx" column)