Skip to main content
OCD
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Alternatively you could use perl,

perl -e '
    $_ = join(" ", (map {chomp; $_} <>));    # Read and join lines
    s/^.*?(".*").*$/$1/;                      # Strip leading and trailing text outside quoted strings
    s/"\s*"/ /g;                              # Merge adjacent quoted strings
    s/\s\s+/ /g;                              # Reduce multiple spaces to one
    print                                     # Output the result
' file

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Alternatively you could use perl,

perl -e '
    $_ = join(" ", (map {chomp; $_} <>));    # Read and join lines
    s/^.*?(".*").*$/$1/;                      # Strip leading and trailing text outside quoted strings
    s/"\s*"/ /g;                              # Merge adjacent quoted strings
    s/\s\s+/ /g;                              # Reduce multiple spaces to one
    print                                     # Output the result
' file

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Alternatively you could use perl,

perl -e '
    $_ = join(" ", (map {chomp; $_} <>));    # Read and join lines
    s/^.*?(".*").*$/$1/;                     # Strip leading and trailing text outside quoted strings
    s/"\s*"/ /g;                             # Merge adjacent quoted strings
    s/\s\s+/ /g;                             # Reduce multiple spaces to one
    print                                    # Output the result
' file
Perl too
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Alternatively you could use perl,

perl -e '
    $_ = join(" ", (map {chomp; $_} <>));    # Read and join lines
    s/^.*?(".*").*$/$1/;                      # Strip leading and trailing text outside quoted strings
    s/"\s*"/ /g;                              # Merge adjacent quoted strings
    s/\s\s+/ /g;                              # Reduce multiple spaces to one
    print                                     # Output the result
' file

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"

Alternatively you could use perl,

perl -e '
    $_ = join(" ", (map {chomp; $_} <>));    # Read and join lines
    s/^.*?(".*").*$/$1/;                      # Strip leading and trailing text outside quoted strings
    s/"\s*"/ /g;                              # Merge adjacent quoted strings
    s/\s\s+/ /g;                              # Reduce multiple spaces to one
    print                                     # Output the result
' file
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

Assuming GNU grep, I would pick out the quoted strings and then join them together

grep -oP '".*?"' file | tr -d '\n' | sed 's/" *"//g'; echo

Result from your example (shortened for brevity)

"v=DKIM1; h=sha256; k=rsa; t=y; p=MIGfMA0GCSqG…QAB"