在SED或AWK编程 [英] Programming in SED or AWK

查看:128
本文介绍了在SED或AWK编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的输入文件

/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 并转换为

I want to read this file using SED or AWK and convert to

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

能不能请你帮/指导呢?

Could you please help / guide on this?

推荐答案

我试图做一个通用的解决方案。您可能需要测试对几种方案。但看起来像它应该为大多数人的工作 -

I have tried to make a generic solution. You may have to test it against several scenarios. But looks like it should work for most of them -

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}

这篇关于在SED或AWK编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆