sed mathing at the end of line by the beging of the next
Hi all,
I have ran into a problem. I have to remove commas at the end of line, but only if the next line does not start with a (or many) space(s). I have the following so far: Code:
sed -e 's/,[ \t]*$//g' aliases thx a lot |
Hi,
Is this what you are looking for: Code:
#!/bin/bash Code:
$ cat infile |
close...
I need to remove the commas and spaces from the end of line ONLY if the next line does NOT start with a space. If a space is found on the next line leave the comma on the previsious line in place Thx for the fast answer |
Hi,
Overlooked the not part.... I'll give it another try but your first and last reply contradict each other. 1) remove commas at the end of line, but only if the next line does not start with a (or many) space(s). 2) remove the commas and spaces from the end of line ONLY if the next line does NOT start with a space. Which is correct 1 or 2? |
Quote:
so i'll reformulate with an example so I'll make it easier I have the folloing file: Code:
cat file |
Ok,
Been playing with this while waiting for your answer. This should work (it does take into account that there could be spaces after the ,): Code:
#!/bin/bash Code:
$ cat infile |
that's it!
THX a lot... I'm strugling with this for 2 days... thx again :) |
You are welcome :)
|
Sed is a line editor. If you have a multi-line pattern, you need to use H (hold) or N (next) to build up more than one line in the pattern space or the hold buffer.
Not sure if this will work in all cases. Maybe your definition should define the patterns expected such as the pattern at the beginning of most lines. It looks like you have output that was line wrapped. Maybe undoing the line wrap is what you need. Try this. I only tested it in your example: Code:
sed '/,$/{N;s/,\n /\n /};' testfile |
the file is a mail aliases, and line wrapping for long aliases is more easy to edit and/or maintain.
This problem apeared after removing some users. |
All times are GMT -5. The time now is 05:46 AM. |