Reputation: 2515
I want to remove a particular string "num= " from the second column of a TAB-DELIMITED text file.
this is a sentence num= 123.45
this is a phrase num= 768.90
I know how to remove "num=" using sed, but I can't seem to be able to remove the space after '='. What I want is this:
this is a sentence 123.45
this is a phrase 768.90
Additionally, if the second column number is greater than 500, I would like to flag the row in a third column, like this:
this is a sentence 123.45 true
this is a phrase 768.90 false
What I tried:
I used awk to get the second column into it's own file and then this:
sed -e s/num=//g -i # Removes just "num="
sed -e s/num= //g -i # I get an error
sed -e s/num=\s//g -i # No effect
Upvotes: 0
Views: 108
Reputation: 37394
Using awk:
$ awk '
BEGIN { FS=OFS="\t" } # set delimiters to tab
{
sub(/num= /,"",$2) # remove num=
print $0,($2+0>500?"true":"false") # output edited record and true/false
}' file
this is a sentence 123.45 false
this is a phrase 768.90 true
Upvotes: 1