Программирование в SED или AWK - PullRequest
0 голосов
/ 20 декабря 2011

Это мой входной файл

/home/edwprod/dnp >ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//|---/g' -e 's/---|/   |/g' | grep -v "^\." 2>/dev/null
|---archive
|---bin
|   |---full_refresh
|   |---to_be_deleted
|---in_dir
|---landing
|   |---archive
|---log
|---tmp
/home/edwprod/dnp >


|---dat_profile_backup
|---mis
|   |---export
|   |   |---home
|   |   |   |---dss1user
|   |   |   |   |---audit
|   |   |   |   |---backup
|   |   |   |   |---bin
|   |   |   |   |   |---To_b_deleted
|   |   |   |   |   |---to_be_deleted
|   |   |   |   |---config
|   |   |   |   |---error
|   |   |   |   |---logs
|   |   |   |   |---plsql
|   |---landing_pad
|   |   |---5.8.7
|   |   |   |---bin
|   |   |   |---lib
|   |   |   |   |---5.8.7
|   |   |   |   |   |---Attribute
|   |   |   |   |   |   |---Handlers
|   |   |   |   |   |   |   |---demo
|   |   |   |   |   |---B
|   |   |   |   |   |---CGI
|   |   |   |   |   |   |---eg
|   |   |   |   |   |---CPAN
|   |   |   |   |   |---Carp
|   |   |   |   |   |---Class
|   |   |   |   |   |   |---ISA
|   |   |   |   |   |---DBM_Filter
|   |   |   |   |   |---Devel
|   |   |   |   |   |---Digest
|   |   |   |   |   |---Encode
|   |   |   |   |   |   |---CN
|   |   |   |   |   |   |---JP
|   |   |   |   |   |   |---KR
|   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |---Unicode
|   |   |   |   |   |---Exporter
|   |   |   |   |   |---ExtUtils
|   |   |   |   |   |   |---Command
|   |   |   |   |   |   |---Constant
|   |   |   |   |   |   |---Liblist
|   |   |   |   |   |   |---MakeMaker
|   |   |   |   |   |---File
|   |   |   |   |   |   |---Spec
|   |   |   |   |   |---Filter
|   |   |   |   |   |   |---Simple
|   |   |   |   |   |---Getopt
|   |   |   |   |   |   |---Long
|   |   |   |   |   |---Hash
|   |   |   |   |   |---I18N
|   |   |   |   |   |   |---LangTags
|   |   |   |   |   |---IO
|   |   |   |   |   |   |---Socket
|   |   |   |   |   |---IPC
|   |   |   |   |   |---List
|   |   |   |   |   |---Locale
|   |   |   |   |   |   |---Codes
|   |   |   |   |   |   |---Maketext
|   |   |   |   |   |---Math
|   |   |   |   |   |   |---BigFloat
|   |   |   |   |   |   |---BigInt
|   |   |   |   |   |---Memoize
|   |   |   |   |   |---NEXT
|   |   |   |   |   |---Net
|   |   |   |   |   |   |---FTP
|   |   |   |   |   |   |---Ping
|   |   |   |   |   |   |---demos
|   |   |   |   |   |---PA-RISC2.0
|   |   |   |   |   |   |---B
|   |   |   |   |   |   |---CORE
|   |   |   |   |   |   |---Data
|   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |---File
|   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |---IO
|   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |---Time
|   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |---XS
|   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |---B
|   |   |   |   |   |   |   |   |---C
|   |   |   |   |   |   |   |---ByteLoader
|   |   |   |   |   |   |   |---Cwd
|   |   |   |   |   |   |   |---Data
|   |   |   |   |   |   |   |   |---Dumper
|   |   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |   |   |---DProf
|   |   |   |   |   |   |   |   |---PPPort
|   |   |   |   |   |   |   |   |---Peek
|   |   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |   |   |---MD5
|   |   |   |   |   |   |   |---DynaLoader
|   |   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |   |   |---Byte
|   |   |   |   |   |   |   |   |---CN
|   |   |   |   |   |   |   |   |---EBCDIC
|   |   |   |   |   |   |   |   |---JP
|   |   |   |   |   |   |   |   |---KR
|   |   |   |   |   |   |   |   |---Symbol
|   |   |   |   |   |   |   |   |---TW
|   |   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |---Fcntl
|   |   |   |   |   |   |   |---File
|   |   |   |   |   |   |   |   |---Glob
|   |   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |   |   |---Call
|   |   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |   |   |---Langinfo
|   |   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |   |   |---SysV
|   |   |   |   |   |   |   |---List
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |   |   |---Base64
|   |   |   |   |   |   |   |---NDBM_File
|   |   |   |   |   |   |   |---ODBM_File
|   |   |   |   |   |   |   |---Opcode
|   |   |   |   |   |   |   |---POSIX
|   |   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |   |   |---encoding
|   |   |   |   |   |   |   |   |---scalar
|   |   |   |   |   |   |   |   |---via
|   |   |   |   |   |   |   |---SDBM_File
|   |   |   |   |   |   |   |---Socket
|   |   |   |   |   |   |   |---Storable
|   |   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |   |   |---Hostname
|   |   |   |   |   |   |   |   |---Syslog
|   |   |   |   |   |   |   |---Time
|   |   |   |   |   |   |   |   |---HiRes
|   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |   |---Normalize
|   |   |   |   |   |   |   |---XS
|   |   |   |   |   |   |   |   |---APItest
|   |   |   |   |   |   |   |   |---Typemap
|   |   |   |   |   |   |   |---attrs
|   |   |   |   |   |   |   |---re
|   |   |   |   |   |   |   |---sdbm
|   |   |   |   |   |   |   |---threads
|   |   |   |   |   |   |   |   |---shared
|   |   |   |   |   |   |---threads
|   |   |   |   |   |---PA-RISC2.0-thread-multi
|   |   |   |   |   |   |---B
|   |   |   |   |   |   |---CORE
|   |   |   |   |   |   |---Data
|   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |---File
|   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |---IO
|   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |---Time
|   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |---XS
|   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |---B
|   |   |   |   |   |   |   |   |---C
|   |   |   |   |   |   |   |---ByteLoader
|   |   |   |   |   |   |   |---Cwd
|   |   |   |   |   |   |   |---Data
|   |   |   |   |   |   |   |   |---Dumper
|   |   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |   |   |---DProf
|   |   |   |   |   |   |   |   |---PPPort
|   |   |   |   |   |   |   |   |---Peek
|   |   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |   |   |---MD5
|   |   |   |   |   |   |   |---DynaLoader
|   |   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |   |   |---Byte
|   |   |   |   |   |   |   |   |---CN
|   |   |   |   |   |   |   |   |---EBCDIC
|   |   |   |   |   |   |   |   |---JP
|   |   |   |   |   |   |   |   |---KR
|   |   |   |   |   |   |   |   |---Symbol
|   |   |   |   |   |   |   |   |---TW
|   |   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |---Fcntl
|   |   |   |   |   |   |   |---File
|   |   |   |   |   |   |   |   |---Glob
|   |   |   |   |   |   |   |   |---Temp
|   |   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |   |   |---Call
|   |   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |   |   |---Langinfo
|   |   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |   |   |---SysV
|   |   |   |   |   |   |   |---List
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |   |   |---Base64
|   |   |   |   |   |   |   |---NDBM_File
|   |   |   |   |   |   |   |---ODBM_File
|   |   |   |   |   |   |   |---Opcode
|   |   |   |   |   |   |   |---POSIX
|   |   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |   |   |---encoding
|   |   |   |   |   |   |   |   |---scalar
|   |   |   |   |   |   |   |   |---via
|   |   |   |   |   |   |   |---SDBM_File
|   |   |   |   |   |   |   |---Socket
|   |   |   |   |   |   |   |---Storable
|   |   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |   |   |---Hostname
|   |   |   |   |   |   |   |   |---Syslog
|   |   |   |   |   |   |   |---Time
|   |   |   |   |   |   |   |   |---HiRes
|   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |   |---Normalize
|   |   |   |   |   |   |   |---XS
|   |   |   |   |   |   |   |   |---APItest
|   |   |   |   |   |   |   |   |---Typemap
|   |   |   |   |   |   |   |---attrs
|   |   |   |   |   |   |   |---re
|   |   |   |   |   |   |   |---sdbm
|   |   |   |   |   |   |   |---threads
|   |   |   |   |   |   |   |   |---shared
|   |   |   |   |   |   |---threads
|   |   |   |   |   |---PA-RISC2.0-thread-multi-LP64
|   |   |   |   |   |   |---B
|   |   |   |   |   |   |---CORE
|   |   |   |   |   |   |---Data
|   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |---File
|   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |---IO
|   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |---Time
|   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |---XS
|   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |---B
|   |   |   |   |   |   |   |   |---C
|   |   |   |   |   |   |   |---ByteLoader
|   |   |   |   |   |   |   |---Cwd
|   |   |   |   |   |   |   |---Data
|   |   |   |   |   |   |   |   |---Dumper
|   |   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |   |   |---DProf
|   |   |   |   |   |   |   |   |---PPPort
|   |   |   |   |   |   |   |   |---Peek
|   |   |   |   |   |   |   |---Digest
|   |   |   |   |   |   |   |   |---MD5
|   |   |   |   |   |   |   |---DynaLoader
|   |   |   |   |   |   |   |---Encode
|   |   |   |   |   |   |   |   |---Byte
|   |   |   |   |   |   |   |   |---CN
|   |   |   |   |   |   |   |   |---EBCDIC
|   |   |   |   |   |   |   |   |---JP
|   |   |   |   |   |   |   |   |---KR
|   |   |   |   |   |   |   |   |---Symbol
|   |   |   |   |   |   |   |   |---TW
|   |   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |---Fcntl
|   |   |   |   |   |   |   |---File
|   |   |   |   |   |   |   |   |---Glob
|   |   |   |   |   |   |   |   |---Temp
|   |   |   |   |   |   |   |---Filter
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |   |   |---Call
|   |   |   |   |   |   |   |---I18N
|   |   |   |   |   |   |   |   |---Langinfo
|   |   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |---IPC
|   |   |   |   |   |   |   |   |---SysV
|   |   |   |   |   |   |   |---List
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |   |   |---Base64
|   |   |   |   |   |   |   |---NDBM_File
|   |   |   |   |   |   |   |---ODBM_File
|   |   |   |   |   |   |   |---Opcode
|   |   |   |   |   |   |   |---POSIX
|   |   |   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |   |   |---encoding
|   |   |   |   |   |   |   |   |---scalar
|   |   |   |   |   |   |   |   |---via
|   |   |   |   |   |   |   |---SDBM_File
|   |   |   |   |   |   |   |---Socket
|   |   |   |   |   |   |   |---Storable
|   |   |   |   |   |   |   |---Sys
|   |   |   |   |   |   |   |   |---Hostname
|   |   |   |   |   |   |   |   |---Syslog
|   |   |   |   |   |   |   |---Time
|   |   |   |   |   |   |   |   |---HiRes
|   |   |   |   |   |   |   |---Unicode
|   |   |   |   |   |   |   |   |---Normalize
|   |   |   |   |   |   |   |---XS
|   |   |   |   |   |   |   |   |---APItest
|   |   |   |   |   |   |   |   |---Typemap
|   |   |   |   |   |   |   |---attrs
|   |   |   |   |   |   |   |---re
|   |   |   |   |   |   |   |---sdbm
|   |   |   |   |   |   |   |---threads
|   |   |   |   |   |   |   |   |---shared
|   |   |   |   |   |   |---threads
|   |   |   |   |   |---PerlIO
|   |   |   |   |   |   |---via
|   |   |   |   |   |---Pod
|   |   |   |   |   |   |---Perldoc
|   |   |   |   |   |   |---Text
|   |   |   |   |   |---Scalar
|   |   |   |   |   |---Search
|   |   |   |   |   |---Switch
|   |   |   |   |   |---Term
|   |   |   |   |   |   |---ANSIColor
|   |   |   |   |   |---Test
|   |   |   |   |   |   |---Harness
|   |   |   |   |   |   |---Simple
|   |   |   |   |   |---Text
|   |   |   |   |   |   |---Balanced
|   |   |   |   |   |   |---TabsWrap
|   |   |   |   |   |---Thread
|   |   |   |   |   |---Tie
|   |   |   |   |   |---Time
|   |   |   |   |   |---Unicode
|   |   |   |   |   |   |---Collate
|   |   |   |   |   |---User
|   |   |   |   |   |---auto
|   |   |   |   |   |   |---POSIX
|   |   |   |   |   |   |   |---SigAction
|   |   |   |   |   |---pod
|   |   |   |   |   |---unicore
|   |   |   |   |   |   |---To
|   |   |   |   |   |   |---lib
|   |   |   |   |   |   |   |---bc
|   |   |   |   |   |   |   |---ccc
|   |   |   |   |   |   |   |---dt
|   |   |   |   |   |   |   |---ea
|   |   |   |   |   |   |   |---gc_sc
|   |   |   |   |   |   |   |---hst
|   |   |   |   |   |   |   |---jt
|   |   |   |   |   |   |   |---lb
|   |   |   |   |   |   |   |---nt
|   |   |   |   |   |---warnings
|   |   |   |   |---site_perl
|   |   |   |   |   |---5.8.7
|   |   |   |   |   |   |---Bundle
|   |   |   |   |   |   |---Carp
|   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |   |---Symdump
|   |   |   |   |   |   |---File
|   |   |   |   |   |   |---HTML
|   |   |   |   |   |   |---HTTP
|   |   |   |   |   |   |   |---Cookies
|   |   |   |   |   |   |   |---Headers
|   |   |   |   |   |   |   |---Request
|   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |---Adapter
|   |   |   |   |   |   |   |   |---Base
|   |   |   |   |   |   |   |   |---Gzip
|   |   |   |   |   |   |   |   |---Zip
|   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |---Uncompress
|   |   |   |   |   |   |   |   |---Adapter
|   |   |   |   |   |   |---LWP
|   |   |   |   |   |   |   |---Authen
|   |   |   |   |   |   |   |---Protocol
|   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |---Net
|   |   |   |   |   |   |   |---HTTP
|   |   |   |   |   |   |---OLE
|   |   |   |   |   |   |---PA-RISC2.0
|   |   |   |   |   |   |   |---Bundle
|   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Policy
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |   |   |---Const
|   |   |   |   |   |   |   |   |   |---GetInfo
|   |   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |   |---ProfileDumper
|   |   |   |   |   |   |   |   |---SQL
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---Win32
|   |   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |---PA-RISC2.0-thread-multi
|   |   |   |   |   |   |   |---Bit
|   |   |   |   |   |   |   |   |---Vector
|   |   |   |   |   |   |   |---Bundle
|   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |---Raw
|   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Policy
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |   |---Oracle
|   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |   |   |---Const
|   |   |   |   |   |   |   |   |   |---GetInfo
|   |   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |   |---ProfileDumper
|   |   |   |   |   |   |   |   |---SQL
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---Date
|   |   |   |   |   |   |   |   |---Calc
|   |   |   |   |   |   |   |   |---Calendar
|   |   |   |   |   |   |   |---HTML
|   |   |   |   |   |   |   |---Win32
|   |   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |   |---Bit
|   |   |   |   |   |   |   |   |   |---Vector
|   |   |   |   |   |   |   |   |---Carp
|   |   |   |   |   |   |   |   |   |---Clan
|   |   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |   |---Raw
|   |   |   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |   |---Oracle
|   |   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |   |   |---Date
|   |   |   |   |   |   |   |   |   |---Calc
|   |   |   |   |   |   |   |   |---Devel
|   |   |   |   |   |   |   |   |   |---StackTrace
|   |   |   |   |   |   |   |   |   |---Symdump
|   |   |   |   |   |   |   |   |---HTML
|   |   |   |   |   |   |   |   |   |---Parser
|   |   |   |   |   |   |   |   |   |---Tagset
|   |   |   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |   |   |---Base
|   |   |   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |   |---LWP
|   |   |   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |   |   |   |---Lite
|   |   |   |   |   |   |   |   |---OLE
|   |   |   |   |   |   |   |   |   |---Storage_Lite
|   |   |   |   |   |   |   |   |---Parse
|   |   |   |   |   |   |   |   |   |---RecDescent
|   |   |   |   |   |   |   |   |---Spreadsheet
|   |   |   |   |   |   |   |   |   |---ParseExcel
|   |   |   |   |   |   |   |   |   |---WriteExcel
|   |   |   |   |   |   |   |   |---Test
|   |   |   |   |   |   |   |   |   |---Exception
|   |   |   |   |   |   |   |   |---URI
|   |   |   |   |   |   |   |   |---XML
|   |   |   |   |   |   |   |   |   |---NamespaceSupport
|   |   |   |   |   |   |---PA-RISC2.0-thread-multi-LP64
|   |   |   |   |   |   |   |---Bit
|   |   |   |   |   |   |   |   |---Vector
|   |   |   |   |   |   |   |---Bundle
|   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |---Raw
|   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Policy
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |   |---Oracle
|   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |   |   |---Const
|   |   |   |   |   |   |   |   |   |---GetInfo
|   |   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |---Gofer
|   |   |   |   |   |   |   |   |   |---Transport
|   |   |   |   |   |   |   |   |---ProfileDumper
|   |   |   |   |   |   |   |   |---SQL
|   |   |   |   |   |   |   |   |---Util
|   |   |   |   |   |   |   |---Date
|   |   |   |   |   |   |   |   |---Calc
|   |   |   |   |   |   |   |   |---Calendar
|   |   |   |   |   |   |   |---HTML
|   |   |   |   |   |   |   |---Win32
|   |   |   |   |   |   |   |---XML
|   |   |   |   |   |   |   |   |---Parser
|   |   |   |   |   |   |   |   |   |---Encodings
|   |   |   |   |   |   |   |   |   |---Style
|   |   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |   |---Bit
|   |   |   |   |   |   |   |   |   |---Vector
|   |   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |   |---Raw
|   |   |   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |   |   |---Zlib
|   |   |   |   |   |   |   |   |---DBD
|   |   |   |   |   |   |   |   |   |---Oracle
|   |   |   |   |   |   |   |   |---DBI
|   |   |   |   |   |   |   |   |---Date
|   |   |   |   |   |   |   |   |   |---Calc
|   |   |   |   |   |   |   |   |---HTML
|   |   |   |   |   |   |   |   |   |---Parser
|   |   |   |   |   |   |   |   |---IO
|   |   |   |   |   |   |   |   |   |---Stringy
|   |   |   |   |   |   |   |   |---LWP
|   |   |   |   |   |   |   |   |---MIME
|   |   |   |   |   |   |   |   |   |---Lite
|   |   |   |   |   |   |   |   |---OLE
|   |   |   |   |   |   |   |   |   |---Storage_Lite
|   |   |   |   |   |   |   |   |---Parse
|   |   |   |   |   |   |   |   |   |---RecDescent
|   |   |   |   |   |   |   |   |---Spreadsheet
|   |   |   |   |   |   |   |   |   |---ParseExcel
|   |   |   |   |   |   |   |   |   |---WriteExcel
|   |   |   |   |   |   |   |   |---URI
|   |   |   |   |   |   |   |   |---XML
|   |   |   |   |   |   |   |   |   |---NamespaceSupport
|   |   |   |   |   |   |   |   |   |---Parser
|   |   |   |   |   |   |   |   |   |   |---Expat
|   |   |   |   |   |   |   |   |   |---SAX
|   |   |   |   |   |   |   |   |   |   |---Expat
|   |   |   |   |   |   |---Parse
|   |   |   |   |   |   |---Spreadsheet
|   |   |   |   |   |   |   |---ParseExcel
|   |   |   |   |   |   |   |---WriteExcel
|   |   |   |   |   |   |---Test
|   |   |   |   |   |   |---URI
|   |   |   |   |   |   |   |---file
|   |   |   |   |   |   |   |---urn
|   |   |   |   |   |   |---WWW
|   |   |   |   |   |   |   |---RobotRules
|   |   |   |   |   |   |---XML
|   |   |   |   |   |   |   |---SAX
|   |   |   |   |   |   |   |   |---PurePerl
|   |   |   |   |   |   |   |   |   |---Reader
|   |   |   |   |   |   |---auto
|   |   |   |   |   |   |   |---Compress
|   |   |   |   |   |   |   |   |---Zlib
|   |   |   |---man
|   |   |   |   |---man1
|   |   |   |   |---man3
|   |   |---E2E_states
|   |   |---bos1
|   |   |---bos2
|   |   |   |---BKP
|   |   |   |---bkp
|   |   |---bos3
|   |   |   |---BKP
|   |   |   |---bkp
|   |   |---bos4
|   |   |   |---BKP
|   |   |   |   |---bkp
|   |   |---bos_cease
|   |   |   |---bos_cease_1
|   |   |   |   |---archive
|   |   |   |   |---log
|   |   |   |   |---rejected
|   |   |   |---bos_cease_2
|   |   |   |   |---archive
|   |   |   |   |---log
|   |   |   |   |---rejected
|   |   |   |---bos_cease_3
|   |   |   |   |---archive
|   |   |   |   |---log
|   |   |   |   |---rejected
|   |   |   |---bos_cease_4
|   |   |   |   |---archive
|   |   |   |   |---log
|   |   |   |   |---rejected
|   |   |   |---bos_xsd
|   |   |   |---log
|   |   |---bos_log
|   |   |---c2b
|   |   |   |---delivered
|   |   |   |---loaded
|   |   |   |---log
|   |   |---c2b_vas_orders
|   |   |---cew
|   |   |   |---housekeep
|   |   |   |---log
|   |   |   |---scripts
|   |   |   |---sent
|   |   |   |---spool
|   |   |---css
|   |   |   |---err
|   |   |   |---loaded
|   |   |   |---log
|   |   |   |---rej
|   |   |   |---tsv
|   |   |---css_orders
|   |   |---domain
|   |   |---exch
|   |   |   |---delivered
|   |   |   |---loaded
|   |   |   |---log
|   |   |   |---rejected
|   |   |---finnead
|   |   |---geneva
|   |   |   |---err
|   |   |   |---loaded
|   |   |   |---log
|   |   |   |---rej
|   |   |   |---txt
|   |   |---he
|   |   |   |---csv
|   |   |   |---latest
|   |   |   |---log
|   |   |---lost+found
|   |   |---munich
|   |   |   |---archive
|   |   |   |---delivered
|   |   |   |---log
|   |   |---odm_css
|   |   |   |---delivered
|   |   |   |---loaded
|   |   |   |---log
|   |   |---oracle
|   |   |   |---InstantClient
|   |   |   |   |---itanium
|   |   |   |   |   |---32bit
|   |   |   |   |   |   |---instantclient_10_2
|   |   |   |   |   |   |   |---sdk
|   |   |   |   |   |   |   |   |---demo
|   |   |   |   |   |   |   |   |---include
|   |   |   |   |   |---64bit
|   |   |   |   |   |   |---instantclient_10_2
|   |   |   |   |   |   |   |---sdk
|   |   |   |   |   |   |   |   |---demo
|   |   |   |   |   |   |   |   |---include
|   |   |   |   |---pa-risc
|   |   |   |   |   |---32bit
|   |   |   |   |   |   |---instantclient_10_2
|   |   |   |   |   |   |   |---sdk
|   |   |   |   |   |   |   |   |---demo
|   |   |   |   |   |   |   |   |---include
|   |   |   |   |   |---64bit
|   |   |   |   |   |   |---instantclient_10_2
|   |   |   |   |   |   |   |---sdk
|   |   |   |   |   |   |   |   |---demo
|   |   |   |   |   |   |   |   |---include
|   |   |---orca
|   |   |   |---affinity
|   |   |   |   |---delivered
|   |   |   |   |---loaded
|   |   |   |   |---rejected
|   |   |   |---brio
|   |   |   |   |---sent
|   |   |   |---log
|   |   |---parb
|   |   |---scheduler
|   |   |   |---cron_backup
|   |   |   |---log
|   |   |---sdp
|   |   |   |---delivered
|   |   |   |---loaded
|   |   |   |---log
|   |   |   |---rejected
|   |   |   |---xsd
|   |   |---vos
|   |   |   |---log

Как построить для этого?

Я хочу прочитать этот файл, используя SED или AWK и преобразовать в

mkdir -p /home/edwprod/dnp/{archive,bin/{full_refresh,to_be_deleted},in_dir,landing/archive,log,tmp}

Не могли бы вы помочь / руководство по этому вопросу?

Ответы [ 2 ]

0 голосов
/ 20 декабря 2011

Я попытался сделать общее решение.Возможно, вам придется проверить его по нескольким сценариям.Но похоже, что он должен работать для большинства из них -

awk -F="|---" '                                                                                                                        
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="|   |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' FILENAME | 
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'

Тест:

[jaypal:~/Temp] cat file
|---archive
|---bin
|   |---full_refresh
|   |---to_be_deleted
|---in_dir
|---landing
|   |---archive
|---log
|---tmp

[jaypal:~/Temp] awk -F="|---" '                                                                                                                        
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="|   |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' file | 
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'
mkdir -p /home/edwprod/dnp/{archive,bin/{full_refresh,to_be_deleted},in_dir,landing/archive,log,tmp}

[jaypal:~/Temp] cat file1
|---bin
|---file_dir
|   |---old
|---in_dir
|---landing
|   |---feed
|---log
|---out_dir
|---prc
|   |---for

[jaypal:~/Temp] awk -F="|---" '                                                                                                                        
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="|   |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' file1 | 
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'
mkdir -p /home/edwprod/dnp/{bin,file_dir/old,in_dir,landing/feed,log,out_dir,prc/for}
0 голосов
/ 20 декабря 2011

Зачем ты это делаешь? При выполнении команды mkdir оболочка сгенерирует серию имен, а отдельными именами будут имена, сгенерированные командой ls -R. Сама команда mkdir не расширяет сжатую нотацию, которую вы ищете. (Существует отдельная дискуссия о том, стоит ли вообще разбирать вывод ls, но мы можем игнорировать это, если ваши имена не будут содержать пробелов и других нечетных символов.)

Итак, вам лучше всего использовать:

echo mkdir -p $(ls -R | sed -n '/:$/{s/:$//;p;}')
...