Hi RavinderSingh13, thank i've tried it with the sample input. But the problem is when i change the input (maintain the exact column only data different) it messed up. Can u explain a bit what the code actually did?
Thanks
---------- Post updated at 12:51 PM ---------- Previous update was at 12:46 PM ----------
As you haven't mentioned which kind of data change you have done, so I can't say about it. Following is the explanation for code.
awk -F"|" ###### Making Field separator as | (pipe)
'{n=split($NF, A," "); ###### using split which is awk's in built utility to split the field/variable accordingly into an array where we could choose our own delimiter, like here I have taken field $NF(which means last field of line), array named A, with delimiter space. So split(Variable/Field/Line, Array_name, delimiter). Also taking a variable named n which will have total number of elements that array A has in it. So that we could use this further in code.
$(NF+1)=A[n-1]} ###### Making a new field next to last field which $NF by making it to $(NF+1) it will add a new field to current last field whose value will be equal to array A's 2nd last element which is actually line's second last field too(Because we have taken space as delimiter.)
1' ###### putting 1 here, awk works on basis of condition and action, so if condition is TRUE action will be performed, here I have made condition TRUE by mentioning as 1 but didn't mention any action so default action which is print in awk will happen so it will print the line.
OFS="|" Input_file ###### Mentioning the output field separator as | and mentioning Input_file here.