Link to home
Start Free TrialLog in
Avatar of hexfusion
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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hexfusion
hexfusion

ASKER

failed to attach full data file.
data.txt
nice