I have a csv file of 28,000 lines. I need to append to each line this string: ,UF, A, Y, 9, U I have an example 8 line file "test2.csv":

10004,Able,Baker,able.baker@notrealemail.com 14634,Charley,Delta,charley.delta@notrealemail.com 12886,Echo,Foxtrot,echo.foxtrot@notrealemail.com 14366,Golf,Hotel,golf.hotel@notrealemail.com 10178,India,Juliet,india.juliet@notrealemail.com 10164,Kilo,Lima,kilo.lima@notrealemail.com 10124,Mike,November,mike.november@notrealemail.com
This is the result that I need:
10004,Able,Baker,able.baker@notrealemail.com,UF, A, Y, 9, U 14634,Charley,Delta,charley.delta@notrealemail.com,UF, A, Y, 9, U 12886,Echo,Foxtrot,echo.foxtrot@notrealemail.com,UF, A, Y, 9, U 14366,Golf,Hotel,golf.hotel@notrealemail.com,UF, A, Y, 9, U 10178,India,Juliet,india.juliet@notrealemail.com,UF, A, Y, 9, U 10164,Kilo,Lima,kilo.lima@notrealemail.com,UF, A, Y, 9, U 10124,Mike,November,mike.november@notrealemail.com,UF, A, Y, 9, U My goal is to perform this appending function within a perl script. I found a site suggesting this type of command formating: <code> perl -ne 'chomp; printf "%sUF,A,Y,9,U\n", $_' test2.csv > final.csv;
It works perfectly. So I tried it within a single line script with strict and warnings. It generated this error:
Bareword found where operator expected at ./test_2.pl line 8, near "'c +homp; printf "%sUF,A,Y,9,U\n", $_' test2" (Missing operator before test2?) syntax error at ./test_2.pl line 8, near "-ne" Execution of ./test_2.pl aborted due to compilation errors
I have no clue how to address this error. I can run this awk ommand at command line and it also works perfectly:
awk '{print $0,"UF,A,Y,9,U"}' OFS="," < test2.csv > final.csv
So, I tried to run the same thing inside a perl script:
print "awk '{print \$0,\"UF,A,Y,9,U\"}' OFS\=\",\" < test2\.csv > fina +l\.csv\n";
It displays to screen without errors but generates zero output and does not create the 'final.csv' file. How do I accomplish appending this string correctly?


In reply to Appending string to all lines by bentrim

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.