Avatar of hexfusion
 asked on

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

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
PerlRegular Expressions

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

failed to attach full data file.

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes