col1 col2 col3 col 4 col 5
wrxwrx 124 jun 3 Sensex.EMEA
wrxwrx 120 jun 4 Emex.US
wrxwrx 130 feb 3 passion.AUS
wrxwrx 145 feb 9 lession.AUS
wrxwrx 130 feb 5 pass.US
wrxwrx 130 feb 8 letter.EMEA
Required out put :
output.txt
col1 col2 col3 col 4 col 5 col6
wrxwrx 124 jun 3 Sensex.EMEA EMEA
wrxwrx 120 jun 4 Emex.US US
wrxwrx 130 feb 3 passion.AUS AUS
wrxwrx 145 feb 9 lession.AUS AUS
wrxwrx 130 feb 5 pass.US US
wrxwrx 130 feb 8 letter.EMEA EMEA
I tired
awk 'NR=FNR {TEM[NR]=$(grep "EMEA \| US \| AUS" file.txt ; next }' {print $1,$2,$3,$4,$5,TEM[NR]}' file.txt output.txt
If can any one help me that would be great thanks!!!!
For first record only, create a new field to hold the field heading.
NR>1{x=$NF;sub(".*\\.","",x);
For all records after the first record, get the characters to the right of the last decimal and assign it to variable x. It does this by using Regular Expression to replace all characters to the left of and including the decimal with nothing.
$(NF+1)=x}1'
Print entire record including the value for the new field.
It appears that both of the solutions will handle your new file if your requirement is to print the characters to the right of the last decimal place in new field at end of each record.