Ram,2368,columbus
Balaji,2368,Portland
Surya,2218,Palo Alto
Chandra,2571,Carson
Ravi,0264,little stone
Sushanth,1261,Menlo park
Rocky,1594,columbus
Q)Print only the names and their hometown for those whose IDs are less than 2000.
CodePudding user response:
Like this?
awk -F, '$2<2000{print $1", "$3}' sasi
Ravi, little stone
Sushanth, Menlo park
Rocky, columbus
Define comma ,
as the field separator, check that field 2 is numerically smaller than 2000, print the 1st and 3rd field if it is.
CodePudding user response:
While this can be done via awk, sed, and other Unix tools, ruby can do everything the other tools can do and cannot do, so you only need to learn one tool.
$ ruby -ne 'a=$_.split(","); print("#{a[0]},#{a[2]}") if a[1].to_i < 2000' sasi
Ravi,little stone
Sushanth,Menlo park
Rocky,columbus