I have a large (2 Million rows) csv file exported from a SQL Server database. I don't have access to the database, and there's some newline character within a column, which makes it difficult to process in R. Sample data like this:playerID,yearID,gameNum,gameID,teamID,lgID,GP,startingPosgomezle01,1933,0,ALS193307060,NYA,AL,1,1ferreri01,1933,0,ALS193307060,BOS,AL,1,2gehrilo01,1933,0,ALS193307060,NYA,AL,1,3gehrich01,1933,0,ALS193307060,DET,AL,1,4dykesji01,1933,0,ALS193307060,CHA,AL,1,5cronijo01,1933,0,ALS193307060,WS1,AL,1,6chapmbe01,1933,0,ALS193307060,NYA,AL,1,7simmoal01,1933,0,ALS193307060,CHA,AL,1,8ruthba01,1933,0,ALS193307060,NYA,AL,1,9In above sample data, some lines breaks into two lines. How to clean it up?  UpdateThe csv file was generated on Microsoft platform. So the line ending is ^m. I made up the sample data on Linux - ended in \n. It's my bad, I didn't make it clear. But I guess I can substitute \n with \r\n.The line break doesn't always appear before a comma, it appears randomly even within a field like .Bill Gates.SolvedStep 1: Remove ^M in the middle of line:perl -pe 's/\r(?!\n)//g'Ref: https://stackoverflow.com/questions/6081465/how-to-remove-carriage-returns-in-the-middle-of-a-lineStep 2: Substitute \n, with , (See @jimmij 's answer below.)perl -p00e 's/\n,/,/g' 
How to detect and remove newline character within a column in a csv file?
awk;perl;r
perl to the rescue:$ perl -p00e 's/\n,/,/g' fileplayerID,yearID,gameNum,gameID,teamID,lgID,GP,startingPosgomezle01,1933,0,ALS193307060,NYA,AL,1,1ferreri01,1933,0,ALS193307060,BOS,AL,1,2gehrilo01,1933,0,ALS193307060,NYA,AL,1,3gehrich01,1933,0,ALS193307060,DET,AL,1,4dykesji01,1933,0,ALS193307060,CHA,AL,1,5cronijo01,1933,0,ALS193307060,WS1,AL,1,6chapmbe01,1933,0,ALS193307060,NYA,AL,1,7simmoal01,1933,0,ALS193307060,CHA,AL,1,8ruthba01,1933,0,ALS193307060,NYA,AL,1,9I assumed here, that the split is always just before comma ,.