Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I know this is a Perl site, but i need help with a one liner. I have a little bash script that cats out a file and tells me if there is a line where the 11th column has more than 6 characters in it. It emails me where there is a bad line in a file - bead meaning that it will break a downstream process. anyhow when i get the email saying that there is a bad file i just log in to the pc via vpn and the I sed out the lines from the file that I get in the email. The bad lines are always in danny.csv not danny1.csv It has been the same lines killing the downstream process for a few weeks, so i put the "sed -i's" into the script and it does it automagically.

for i in danny.csv danny1.csv do cat /come/and/play/with/$i | perl -ne 'print if length((split /,/)[10 +]) > 6' | mail -s "danny.csv bad line" casper@casperr.com done #it would be nice to find a perl change the file in place sed -i '/D,642,0642,UBF,EVL,,M,,S,S,FOREVER,213,213,/d' /come/and/pla +y/with/us/danny.csv sed -i '/D,642,0642,UBF,EVL,,M,,S,S,QSP-U=C,4,4,/d' /come/and/play/wi +th/us/danny.csv

However when a new line gets put into this file, I am going to have to log in and take out the line. SO I have been trying to write a perl one liner that will edit the file in place, like sed, and make a backup of the file. I just need a perl one liner that will delete any line where the 11th columns has more than 6 characters in it.

perl -p -i.bak -e 's/\,\w{7}\,//g - which does not work.

I tried something like this:

perl -nle 'print if /\,\w{7}\,/' /come/and/play/with/us/danny.csv

but that does not catch the QSP-U=C and it catches more lines than just the FOREVER. for a solutinog I need to focus on the the 11th column.


In reply to perl one liner for csv file one field by MrTEE

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found