Reputation: 381
I have a large tab delimited text file like this:
Item Label1 Label2 Label3
1 Pro01 cake wine Toy
2 Pro02 milk curd butter
3 Pro03 rice basum white
4 Pro04 tomma onion root
I just want to remove the contents from the first column and replace it with the second column without removing the header.
Item Label1 Label2 Label3
Pro01 cake wine Toy
Pro02 milk curd butter
Pro03 rice basum white
Pro04 tomma onion root
Upvotes: 0
Views: 463
Reputation: 26471
Similar to the other solution:
awk '{print (NR>1?substr($0,1+index($0,"\t")):$0)}' file
Upvotes: 2
Reputation: 5372
As I said in my comment, you can simply do:
awk 'BEGIN{FS="\t";OFS="\t"}NR==1{print}NR>1{$1=""; print substr($0,2)}' file.txt
You probably want to save the output to a new file as well:
awk 'BEGIN{FS="\t";OFS="\t"}NR==1{print}NR>1{$1=""; print substr($0,2)}' file.txt > newfile.txt
And here is the command above in a structured way for better readability:
awk '
BEGIN {
FS="\t";
OFS="\t"
}
NR==1 {
print
}
NR>1 {
$1="";
print substr($0,2)
}' file.txt > newfile.txt
Upvotes: 0