1

I would like to export data from zimbra server, but it's export data in every new lines, my command:
zmprov -l gaa -v domain.com | grep -e "zimbraForeignPrincipal: " -e "zimbraTwoFactorAuthEnabled: " -e "^mail: "

but the result looks like:
email:
zimbraForeignPrincipal:
zimbraTwoFactorAuthEnabled
Is any way to have email with related attributes in one line?

zuku
  • 61
  • 1
  • 7

1 Answers1

0

Use awk:

zmprov -l gaa -v domain.com | \
grep -e "zimbraForeignPrincipal: " -e "zimbraTwoFactorAuthEnabled: " -e "^mail: " |\
awk '{delim=(NR%2?"\n":" ");txt=(NR==1?"":txt delim) $0}END{print txt}'

It does the following:

  1. Sets the delimiter based on the current line number: if it is odd, then the delimiter is a newline, if it is even, the delimiter is a space (this is the delim=(NR%2?"\n":" ") part).
  2. Collects all lines into a variable named txt. Each line is prepended with the variable itself (i. e. the collected lines so far), and the delimiter from the previous point, unless this is the first line, in which case, an empty string is prepended instead (the txt=(NR==1?"":txt delim) $0 part)
  3. Finally, the variable txt is printed.
Lacek
  • 7,233
  • 24
  • 28