troubleshooting Question

Perl reqular expression remove commented lines and change tab delimited to csv

Avatar of hexfusion
hexfusion asked on
PerlRegular Expressions
3 Comments1 Solution442 ViewsLast Modified:
I want to take a file that has a series of "#" commented lines then tab delimited content.  What I would like to do is use regular expression and perl to input the datafile and output only the USGS line in csv format with no blank lines.  I fount a nice regex that changes the file to csv but having issues isolating that single USGS line.  Thank you!

perl -lpe 's/"/""/g; s/^|$/"/g; s/\t/","/g' < getme.txt > output.csv

Example content :
*full datafile attached

#    DD parameter   Description
#    01   00060     Discharge, cubic feet per second
#    02   00065     Gage height, feet
# Data-value qualification codes included in this output:
#     P  Provisional data subject to revision.
      agency_cd   site_no datetime    tz_cd   01_00060    01_00060_cd 02_00065    02_00065_cd
     5s  15s 20d 6s  14n 10s 14n 10s
      USGS    01417000    2013-04-06 09:45    EST 80  P   2.95    P
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros