我试图在分号前基于反斜杠过滤此文件,例如过滤下面的文件以获得分号前最多包含六个反斜杠的行
\\Filehomeserver\homefolder\eduardo\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI (0x03);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Thumbs.db;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)
\\Filehomeserver\homefolder\eduardo\My Documents\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\My Documents\SametimeChatHistory\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\eduardo.id;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)
期望的输出
\\Filehomeserver\homefolder\eduardo\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI (0x03);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Thumbs.db;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)
\\Filehomeserver\homefolder\eduardo\My Documents\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
我试图运行
findstr /r "\\\\.*\\.*\\.*\\;"
\\Filehomeserver\homefolder\eduardo\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI (0x03);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\My Documents\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\My Documents\SametimeChatHistory\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
但它不起作用,它带来的线路比我想要的多,如果有人对windows findstr或awk / sed有任何其他想法我会很感激
答案 0 :(得分:0)
仅在第一个分号前显示带有六个反斜杠的行。如果需要在分号前保留所有行小于或等于6,请将if语句中的==
更改为<=
。
$ awk -F';' '{if (split($1,a,"\\") == 7) print $0;}' test
\\Filehomeserver\homefolder\eduardo\My Documents\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\eduardo.id;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)
正如@Ed Morton在下面的评论中指出的那样,这可以简化为
awk -F';' 'split($1,a,/\\/) <= 7' test
答案 1 :(得分:0)
$ awk -F';' '{k=$1} gsub(/\\/,"",k)<=6' file
\\Filehomeserver\homefolder\eduardo\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI (0x03);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Thumbs.db;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)
\\Filehomeserver\homefolder\eduardo\My Documents\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:OI,CI,IA (0x13);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:OI,CI,IA (0x13)
\\Filehomeserver\homefolder\eduardo\Notes ID file\eduardo.id;USDOM\eduardo : Allowed CHGE:EWXD (0x001301BF) Flags:IA (0x10);USDOM\sec_&Conf_group: Allowed FULL:EWXPOD (0x001F01FF) Flags:IA (0x10)