[SATLUG] how to use tr to remove newlines after '--'

pcdls.ronin pcdls.ronin at gmail.com
Sat May 29 12:01:06 CDT 2010

Don Davis wrote:
>>>> pcdls
>> Your input text file looks like this?
>> 1 --
> Yes. Thank you.

## With an input like this pasted into foobar.txt ##
## Beginning  of  foobar.txt - Comments shown here are not in the file. ##
1 --
## End of foobar.txt ##
## Assumes \n (hex: 0A) and no other endline symbols ##

I tried this command, as follows, to remove the \n from the end of each 
line that ends in '--': In otherwords, "--<\n>" which can be represented 
as ASCII <2D><2D><2A>, if there is any other character string between 
the -- and the '\n', then you may need to evaluate your input file for 
whether you might have a space following your '--' or another 
non-visible symbol that separates your '--' from '/n'.  In that case, 
the command should be updated to reflect this criteria.

Anyway, the command I used was as follows:

sed -n '1h;2,$H;${g;s/--\n/--/g;p}' foobar.txt > test.txt

After execution, opened up test.txt and found the following (comments 
shown were not in the file):
## Beginning of test.txt ##
1 ------NOT
## End of test.txt ##

If you don't get this, then evaluate your input text file. Under the 
criteria that I defined for this email, it appears this particular 
command may help you out.


More information about the SATLUG mailing list