Score:0

find a number after a special character and multiply it by awk

eg flag

I have a file:

"UDP", "x", 12880, "any", "any", x, 0.0.0.0/0, 0.0.0.0/0, {85000, drop, -1, fast+dsample:1000}, {1m, alert, -1, none}

How can I change 85000 number which is after "{" and multiply it by a value to reduce it by awk. like: 85000*0.75= 63,750 Final line should be:

"UDP", "x", 12880, "any", "any", x, 0.0.0.0/0, 0.0.0.0/0, {63750, drop, -1, fast+dsample:1000}, {1m, alert, -1, none}
waltinator avatar
it flag
Just that once, or on multiple lines? Just `{85000` or `'{[0-9]+'`?
masoud hanifehzadeh avatar
eg flag
I want to use it in a bash script that change the given line. so just for a line.
Score:1
hr flag

With any awk (for example, mawk):

mawk 'match($0,/{[0-9]+/) {
  d = substr($0,RSTART+1,RLENGTH)
  $0 = substr($0,1,RSTART) 0.75*d substr($0,RSTART+RLENGTH)
} 1' file
"UDP", "x", 12880, "any", "any", x, 0.0.0.0/0, 0.0.0.0/0, {63750, drop, -1, fast+dsample:1000}, {1m, alert, -1, none}

With GNU awk:

gawk 'match($0,/([^{]*{)([0-9]+)(.*)/,a){$0 = a[1] 0.75*a[2] a[3]} 1' file
"UDP", "x", 12880, "any", "any", x, 0.0.0.0/0, 0.0.0.0/0, {63750, drop, -1, fast+dsample:1000}, {1m, alert, -1, none}

Alternatively, with perl

perl -pe 's/(?<={)\d+/0.75 * $&/e' file
"UDP", "x", 12880, "any", "any", x, 0.0.0.0/0, 0.0.0.0/0, {63750, drop, -1, fast+dsample:1000}, {1m, alert, -1, none}
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.