In other words, how can I join multiple records/lines (2 or more) where the backslash character has been used to extend across multiple lines - using standard UNIX tools such as sed, awk, grep, sh, etc.
The actual application in this instance is joining backslashed multiple lines from the sudoers file.
This seems to work fine (although only with gsed and not the sed that comes with Solaris 10).
Some of the lines that follow the backslah contain leading spaces/tabs and the backslahes are also preceded by a space. This is what I've found has worked, although it doesn't look particularly pretty:
# sed 's/[1]//g' /etc/sudoers | \ # space & tab between brackets
gsed ':a;N;s/\\\n/ /;ba' | \
sed 's/,[ ]/,/g' # space & tab between brackets
Can I get all of this into a single sed statement?
Also, could you explain what't happening in the gsed statement you piointed out?
This should get rid of spaces around the backslash:
sed ':a;N;s/[ \t]*\\\n[ \t]*/ /;ba' infile
It creates a label a ( a: )
It then joins two lines ( N )
After that leadings space before and after a \ followed by a linefeed (\n) get replaced by a single space
Then it branches (b) to label a.
OK, you've given me pretty much exactly what I asked for but this has only highlighted the fact that I mis-stated exactly what I wanted. Ultimately, I'm trying to generate a list of hosts that are represented in the sudoers file. This sed statement (which actually only works if I use gsed on my Solaris 10 host) now leaves me with something like this:
OK, I can removed blank lines with grep or awk and I can chop off everything up to the = character with another sed statement and I might use tr, for example, to replace all the , characters with a newline character and I'm sure this would all get me what I want.
But ... could it ALL be done in a single command? List every host that's represented in the sudoers file?
CDM
---------- Post updated at 11:22 AM ---------- Previous update was at 11:11 AM ----------