Eduardo
Eduardo

Reputation: 397

awk/sed broken line how to fix and move some lines

I have a few lines that are broken and I want those lines to be moved up to the prior line

I need help to fix this file text Source:

    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\Ser
             vice_Legal 
    Access : BUILTIN\Administrators Allow  FullControl
             MLIDDOMAIN1\Domain Admins Allow  FullControl
             MLIDDOMAIN1\acl_corp_gs_legal Allow  Modify, Synchronize
    -----------------------
    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\balco 
    Access : Everyone Allow  FullControl
             Everyone Allow  268435456
    -----------------------
    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\BCDRP
             lanning 
    Access : Everyone Allow  FullControl
             Everyone Allow  268435456
    -----------------------

Expected result:

    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\Service_Legal 
    Access : BUILTIN\Administrators Allow  FullControl
    -----------------------
    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\balco 
    Access : Everyone Allow  FullControl
             Everyone Allow  268435456
    -----------------------
    Path   : Microsoft.PowerShell.Core\FileSystem::\\eiesc1\BCDRPlanning 
    Access : Everyone Allow  FullControl
             Everyone Allow  268435456
    -----------------------

I only was able to run awk "/Path/{a=1;next}/Access/{a=0}a" to find which are the lines that are broken, but I do not know how to move those lines up.

Upvotes: 2

Views: 214

Answers (2)

Beta
Beta

Reputation: 99144

sed '/^Path/{N;s/\n         //;}'

Upvotes: 1

Etan Reisner
Etan Reisner

Reputation: 81012

You want to hold off on printing your Path lines until you've seen the next line and if the next line isn't an Access line then you want to print the two lines together.

Something like:

/Path/ {
    a=$0
    next
}

a && !/Access/ {
    gsub(/^ */, "")
    printf "%s",a
    print
    a=""
    next
}

1

Upvotes: 1

Related Questions