sed / awk script to delete the two digits from first 3 digits

Hi All ,

I am having an input file as stated below

5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011
611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011
3486 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 100
4611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 100
4663 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011
1868 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 100
1718 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 100
5670 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 100

I need to delete the last two digits from the field 7 in the above stated file

Output file

5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 0
611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 0
3486 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 1
4611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 1
4663 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 0
1868 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 1
1718 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 1
5670 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 1

I tried to extract it

awk'/PATTERN { print $7}' input
How to delete the last two digits 

Help me out - I see three fields only, not 7. To remove two trailing digits from $3 , try

awk '{sub (/..$/, _, $3)} 1' file
1 Like

The example file only has 3 fields not 7.

awk - remove last two digits from field 3:

awk '{gsub(/[0-9][0-9]$/,"",$3)} 1' infile

sed - remove last two digits on line

sed 's/[0-9][0-9]$//' infile
1 Like

Hi Chubler ,

Thanks a lot ! How can extract the first and third digits ,
I am trying below code but its not working

Its going to the last character of the line and from there its removing second last and last digits
How to remove the middle one
For example if it is 100
I need extract first and third
10

sed 's/[0-9]$//' infile

I would use capture groups like this:

sed 's/\([0-9]\)[0-9]\([0-9]\)$/\1\2/' infile
1 Like