Wednesday, April 13, 2022

[SOLVED] How to sort column values in csv file using shell script or command?

Issue

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?


Solution

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


Answered By - pmf
Answer Checked By - Pedro (WPSolving Volunteer)