Home > Software design >  How to sort column values in csv file using shell script or command?
How to sort column values in csv file using shell script or command?

Time:03-04

I have a csv file with the below values:

IP        Code
10.0.0.1  200
10.2.0.1  400
10.3.0.2  100
10.2.3.1  201

I want to extract IPs whose code is either 200 or more than that. What can be the simplest way to do it in linux?

CodePudding user response:

A bash solution:

tail -n  2 file.csv |
while read -r ip code; do ((code >= 200)) && echo "$ip"; done
10.0.0.1
10.2.0.1
10.2.3.1

CodePudding user response:

Is awk an option?

awk 'NR>1 && $2>=200 {print $1}' file.csv
10.0.0.1
10.2.0.1
10.2.3.1
  • Related