0

I have a CSV file that has record separator of ,\n. One of the columns, has the possibility of containing tabs and new lines, which I wish to remove. How do I remove these chars (\t\n\r) using sed and/or awk, until encountering the record separator?

1 Answer 1

2

Here you go:

cat input_file | tr -d '\r\t' | sed ': loop_start; /,$/b; N; s/\n//; b loop_start'

Explanation:

  1. tr is used to delete (-d) all \r and \t chars.
  2. Then sed loops (: loop_start; ...; b loop_start) and
  3. joins all lines (N) and
  4. removes the newline (s/\n//)
  5. until it finds the record separator (/,$/) and
  6. branches to the end of the script (b) where it will start the script over with the next line of input.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.