0

Kindly modify my script, because I want to search the word "dBm" in Column 1,3, and 4 of File.csv and return all unmatched lines/records 'cause "dBm" need to be deleted on the file.

cat File.csv | grep -v dBm | sort -u -t '|' -k 1,1 -k 3,4 > Result.csv

Sample File.csv
RefNum|Date|Info|LTC|ICD|MLBB
ABC123|010119|19 dBm||Milk|MII9
DEF456|010119|21|-5 dBm|Choco|KK20
GHI789|010219|||C2|AA30
JKL111|010219|54|17||SK10

Sample Result.csv
RefNum|Date|Info|LTC|ICD|MLBB
GHI789|010219|||C2|AA30
JKL111|010219|54|17||SK10

Badly needed you're help! Cheers.

  • why not egrep -v dBm File.csv > Result.csv? do the other columns take dBm value as well and should not be removed? – Bart Jun 27 at 9:03
  • Yes, other column takes "dBm" but I only need the string should be search only in Column 1,3,and 4. – Ace Jun 27 at 9:07
5

Using awk to extract the lines that does not contain the string dBm as a substring in columns 1, 3, or 4:

awk -F '|' '!($1 ~ /dBm/ || $3 ~ /dBm/ || $4 ~ /dBm/)' file

Given your first piece of data, this would output

RefNum|Date|Info|LTC|ICD|MLBB
GHI789|010219|||C2|AA30
JKL111|010219|54|17||SK10

The awk program matches dBm against each of the three columns, and if there is no match against any of them, it outputs the original line.

  • Great! It works fine! Cheers. – Ace Jun 27 at 9:16
0
$ awk -F'|' '($1 FS $3 FS $4) !~ /dBm/' file
RefNum|Date|Info|LTC|ICD|MLBB
GHI789|010219|||C2|AA30
JKL111|010219|54|17||SK10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.