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":
This is the result that I need: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
It works perfectly. So I tried it within a single line script with strict and warnings. It generated this error: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;
I have no clue how to address this error. I can run this awk ommand at command line and it also works perfectly: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
So, I tried to run the same thing inside a perl script:awk '{print $0,"UF,A,Y,9,U"}' OFS="," < test2.csv > final.csv
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?print "awk '{print \$0,\"UF,A,Y,9,U\"}' OFS\=\",\" < test2\.csv > fina +l\.csv\n";
In reply to Appending string to all lines by bentrim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |