Skip to main content
3 of 5
added 2772 characters in body
ntropi
  • 37
  • 1
  • 3

How to remove \n in a string

I have a tab delimited text file where the 23rd column with string has \n in it which causes it to break to the next line.

I opened the text file in vi and enabled white space characters and I can see that the values in DESCR2 field have blank lines breaking the string.

ACCTMO DESCR2 3 Line 3 "ABC

123 " TEST 3 "ABC

123" TEST 3 "ABC

" TEST

The string is contained within tab delimited characters and I am trying to remove the \n and have the string concatenate to ABC 123 while still in 1 field .

I have tried tr -d '\n' < file.txt but that would make all the lines into 1 line. I want to only remove \n\n from that column.

I also tried sed 's/\n\n//' file.txt but it has no effect. I am able to search and replace \n\n in vi but I can't get the same result with sed.

ntropi
  • 37
  • 1
  • 3