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

pcdls.ronin pcdls.ronin at gmail.com
Sat May 29 11:58:31 CDT 2010


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

## With an input like this pasted into foobar.txt ##
## Beginning  of  foobar.txt - Comments shown here are not in the file. ##
1 --
--
-- 
NOT
SCORED --
--
NO
## 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
SCORED ----NO
## 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.

pcdls



More information about the SATLUG mailing list