Extracting Characters and Mathematical Computation

I have a file with 1 record only and i.e. "Ashish|Bhasin|30000|END", I want to extract the first three characters of the third column and divide it by 10, so in the above case the answer should be 30.
I am using cut command to get 30000 out but not being able to use it further to divide it by 10.
Any bits?

Showing Answers 1 - 5 of 5 Answers


  • Feb 28th, 2017

middle=`cut -d| -f3 Sample_Divide|cut -c1-3`

  Was this answer useful?  Yes

suryakanta sahoo

  • Mar 27th, 2017

awk -F "|" {print substr($3,1,3)/10} file
here ($3,1,3) will get 300 and again 300 will divide by 10 to get 30.

  Was this answer useful?  Yes


  • Jun 23rd, 2017

expr `echo -e "Ashish|Bhasin|30000|END" | cut -d| -f3` / 10

  Was this answer useful?  Yes


  • Sep 7th, 2017

expr `echo -e "Ashish|Bhasin|30000|END" | cut -d"|" -f3 | awk { print substr($0, 0, 3) }` / 10

  Was this answer useful?  Yes


  • Oct 27th, 2017

awk -F | {print substr($3, 0, 3)/10} filename

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions