• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


25 Mar, 2025

Updated at 20 May, 2025

Bash script for extracting specific fields from .txt

I have a .txt file from which I want to extract all unique stop_id and associated coordinates. Here's a sample of the first few lines:

stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,stop_serial_number 12,12,PAKI AVE + PONI MOI RD,,21.261225,-157.818181,,http://hea.thebus.org/nextbus.asp?s=12,,,201 13,13,PAKI AVE + DIAMOND HEAD TENNIS CTR,,21.263524,-157.818523,,http://hea.thebus.org/nextbus.asp?s=13,,,312 14,14,PAKI AVE + NOELA ST,,21.266265,-157.816826,,http://hea.thebus.org/nextbus.asp?s=14,,,420 15,15,PAKI AVE + PAKI PLAYGROUND,,21.267915,-157.816033,,http://hea.thebus.org/nextbus.asp?s=15,,,520

For example, on the first entry I would want to extract 12 and (21.261225, -157.818181). The text file contains ~ 4000 entries in this same format. I'm pretty much a rookie when it comes to bash so I would love an answer that explains syntax well. Thanks