Reputation: 92
I have a sed script which will read in a file and, if a line begins with a space, remove the preceding line break and the matched whitespace so that that line and the preceding line are joined together.
sed -e :a -e '$!N;s/\n / /;ta' -e 'P;D' input_file_name.txt
Is there any way to have javascript do the same using regular expressions?
I am reading in the file using the HTML5 File API.
Upvotes: 1
Views: 2212
Reputation: 33918
Easiest way is to read the whole file and then do a replace like:
content = content.replace(/\r?\n /g, ' ');
If the file fits in memory that is.
Upvotes: 4