0

I have a set of data on a Linux machine:

i_dfi_row_cmd_p1_d[0] ctrl_soft_phy_inst/hbm_ch_tile_4_hbm_tile_inst/o_phy_row_cmd_p1[0] -assign { 0 [ expr 137.88 - 59.248 ]}

I want to perform an arithmetic operation for -assign { 0 [ expr 137.88 59.248 ]} like I want to add X value to 59.248

What I tried to perform this operation is

awk '{print $6+3}' filename # its not giving expected answer

I tried some changes and commands that I found on Stack Overflow but I haven't achieved what I want. How can I do this?

10
  • 1
    What is "X value"? What is "expected answer"? Oct 18, 2022 at 14:56
  • What is $6? 59.248 is the tenth space-separated field if that is a line from your file. Does awk '{print $10 + 3}' give what you expect?
    – terdon
    Oct 18, 2022 at 15:10
  • I suspect that $6 is not what you want. In the sample line you provided, $6 is "[". What are you expecting "[" + 3 to be?
    – A. R.
    Oct 18, 2022 at 15:16
  • "I tried some changes and commands that I found on Stack Overflow" - what did you try? We weren't with you so didn't see what you tried. Oct 18, 2022 at 15:27
  • @glennjackman X is a constant value Oct 19, 2022 at 4:20

1 Answer 1

0

As the commenters have pointed out, you really want to print position 10 ($10) of the string. Using that you can easily add your x value.

Here is a small example:

echo "i_dfi_row_cmd_p1_d[0] ctrl_soft_phy_inst/hbm_ch_tile_4_hbm_tile_inst/o_phy_row_cmd_p1[0] -assign { 0 [ expr 137.88 - 59.248 ]}" | awk '{print $10 + 20}'

This will yield the result 79.248. As you can see, I simply echoed the line of text provided in your original post printing $10 and adding the value 20 to it.

2
  • cat all_pin | awk '{$4=""; print $0}' all_pin | awk '{print "eval " $0}' all_pin | sed -f transform.sed all_pin | awk '{print $10+100}' all_pin this is my command and i am struck at the last command that you gave me. Oct 19, 2022 at 12:01
  • 1
    @SanthoshNayakD. please add all this to your question and make sure to include i) a few lines from all_pin and ii) the exact output you want from those lines. You don't need cat file if you have awk '{command}' file. And we have no idea what transform.sed all_pin does so we will need to see that too.
    – terdon
    Oct 19, 2022 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .