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
Here you go:
cat input_file | tr -d '\r\t' | sed ': loop_start; /,$/b; N; s/\n//; b loop_start'
Explanation:
tris used to delete (-d) all\rand\tchars.- Then sed loops (
: loop_start; ...; b loop_start) and - joins all lines (
N) and - removes the newline (
s/\n//) - until it finds the record separator (
/,$/) and - branches to the end of the script (
b) where it will start the script over with the next line of input.