Skip to main content
deleted 14 characters in body
Source Link
jesse_b
  • 41.5k
  • 14
  • 108
  • 162

Using awk:

awk '{ for (i=1;i<=NF;i++) { if ($i ~ /num2=/) {sub(/num2=/, "",$4 $i); $4="num2="$4$i="num2="$i-5; print} } }' file

This removes the num2= from the 4thwill loop through each column (leaving just a number). Then re-addsof each line looking for the column that contains num2= back to the column while subtracting 5 from the number.

The problem is you have done nothing to define RANDOM TEXT so I have a feeling the column you want to work with either won't be in column 4 or won't consistently be in When it finds that column 4.it will:

  1. Remove num2= - sub(/num2=/, "", $i)
  2. Redefine that column as num2={oldnum-5} - $i="num2="$i-5
  3. Print the line - print

Using awk:

awk '{sub(/num2=/,"",$4); $4="num2="$4-5; print}' file

This removes the num2= from the 4th column (leaving just a number). Then re-adds the num2= back to the column while subtracting 5 from the number.

The problem is you have done nothing to define RANDOM TEXT so I have a feeling the column you want to work with either won't be in column 4 or won't consistently be in column 4.

Using awk:

awk '{ for (i=1;i<=NF;i++) { if ($i ~ /num2=/) {sub(/num2=/, "", $i); $i="num2="$i-5; print} } }' file

This will loop through each column of each line looking for the column that contains num2=. When it finds that column it will:

  1. Remove num2= - sub(/num2=/, "", $i)
  2. Redefine that column as num2={oldnum-5} - $i="num2="$i-5
  3. Print the line - print
Source Link
jesse_b
  • 41.5k
  • 14
  • 108
  • 162

Using awk:

awk '{sub(/num2=/,"",$4); $4="num2="$4-5; print}' file

This removes the num2= from the 4th column (leaving just a number). Then re-adds the num2= back to the column while subtracting 5 from the number.

The problem is you have done nothing to define RANDOM TEXT so I have a feeling the column you want to work with either won't be in column 4 or won't consistently be in column 4.