Modifying output column

Hi friends,
I have file as follow

D1    pin16I    pin20I
R1    pin20F    pin20D
VCC1    pin20A    pin16G

I want to modify it second and third column.
I want to just change the last character of 2nd and 3rd column with some condition.
The condition is if last char of second column is in between [A-E] then print e.g pin16A. However if character is between [F-J] then print it as pin16F. This condition is for all pin not just for pin16 its for all pin.

Thanks and Regards,

what have you tried so far?

just a hint: you can extract the last character of a string by something like below.

echo $string| awk '{print substr($0,length($0),1)}'

@diehard
With 28 posts, you should now that you should use code tags
And also you should post an example output.

This should work, but its some ugly.

awk '	{
	printf "%s ",$1
	}
	{	
	if ($2~/pin[0-9][0-9][A-E]/) printf "%.5sA ",$2; 
	else if ($2~/pin[0-9][0-9][F-J]/) printf "%.5sF ",$2;
	else printf "error "
	}
	{	
	if ($3~/pin[0-9][0-9][A-E]/) printf "%.5sA\n",$3; 
	else if ($3~/pin[0-9][0-9][F-J]/) printf "%.5sF\n",$3;
	else printf "error\n"
	}
	' file
D1 pin16F pin20F
R1 pin20A pin20A
VCC1 pin20A pin16F
1 Like

Thanks man!!!!!!

Actually I used it after long time so forget to use code tag.Sorry for that.

Thanks Again!!!!

Some more clean version that can be expanded if needed.

awk '	{ printf $1; test($2); test($3); print "" }

	function test(num)
	{if (num~/pin[0-9][0-9][A-E]/) printf " %.5sA",num; 
	else if (num~/pin[0-9][0-9][F-J]/) printf " %.5sF",num;
	else printf " error"}
	' file

Thanks!!!
I was just searching for %.5sA but didn't get much on it in awk.
Can you let me know what exactly it is.
If I use pin[0-9][A-E] then what should come in place of %.5sA

printf " %.5sA",num

This prints the num ($2 or $3) with a formatting telling it to only print the 5 first characters. This strips away the last character A-J , so we can then replace it with in as this example A

pin20D	pin20	pin20A
	%.5s	A
1 Like

Thanks....It solve my problem