我想删除换行符并使用java点击文件中的空格。 删除后将其格式化为单行。
输入:
12545|Logoff|MAVENSI8-PC|NULL|4634|4634|4|(S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,3)|Security|An account was logged off.
Subject:
Security ID: S-1-5-21-2692671718-3285579559-3264406991-1000
Account Name: MAVENSI8
Account Domain: MAVENSI8-PC
Logon ID: 0x2e9030
Logon Type: 3
This event is generated when a logon session is destroyed. It may be positively correlated with a logon event using the Logon ID value. Logon IDs are only unique between reboots on the same computer.|46032|Microsoft-Windows-Security-Auditing|20140605041853.569120-000|20140605041853.569120-000|Audit Success|(null)
12544|Logon|MAVENSI8-PC|NULL|4624|4624|4|(S-1-0-0,-,-,0x0,S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,3,NtLmSsp ,NTLM,SRV01,{00000000-0000-0000-0000-000000000000},-,NTLM V1,128,0x0,-,192.168.1.3,36878)|Security|An account was successfully logged on.
Subject:
Security ID: S-1-0-0
Account Name: -
Account Domain: -
Logon ID: 0x0
Logon Type: 3
New Logon:
Security ID: S-1-5-21-2692671718-3285579559-3264406991-1000
Account Name: MAVENSI8
Account Domain: MAVENSI8-PC
Logon ID: 0x2e9030
Logon GUID: {00000000-0000-0000-0000-000000000000}
Process Information:
Process ID: 0x0
Process Name: -
Network Information:
Workstation Name: SRV01
Source Network Address: 192.168.1.3
Source Port: 36878
Detailed Authentication Information:
Logon Process: NtLmSsp
Authentication Package: NTLM
Transited Services: -
Package Name (NTLM only): NTLM V1
Key Length: 128
This event is generated when a logon session is created. It is generated on the computer that was accessed.
The subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.
The logon type field indicates the kind of logon that occurred. The most common types are 2 (interactive) and 3 (network).
The New Logon fields indicate the account for whom the new logon was created, i.e. the account that was logged on.
The network fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.
The authentication information fields provide detailed information about this specific logon request.
- Logon GUID is a unique identifier that can be used to correlate this event with a KDC event.
- Transited services indicate which intermediate services have participated in this logon request.
- Package name indicates which sub-protocol was used among the NTLM protocols.
- Key length indicates the length of the generated session key. This will be 0 if no session key was requested.|46031|Microsoft-Windows-Security-Auditing|20140605041823.673410-000|20140605041823.673410-000|Audit Success|(null)
12548|Special Logon|MAVENSI8-PC|NULL|4672|4672|4|(S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,SeImpersonatePrivilege
输出:
12545|Logoff|MAVENSI8-PC|NULL|4634|4634|4|(S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,3)|Security|An account was logged off.Subject:Security ID: S-1-5-21-2692671718-3285579559-3264406991-1000 Account Name: MAVENSI8 Account Domain: MAVENSI8-PC Logon ID: 0x2e9030Logon Type: 3This event is generated when a logon session is destroyed. It may be positively correlated with a logon event using the Logon ID value. Logon IDs are only unique between reboots on the same computer.|46032|Microsoft-Windows-Security-Auditing|20140605041853.569120-000|20140605041853.569120-000|Audit Success|(null)
12544|Logon|MAVENSI8-PC|NULL|4624|4624|4|(S-1-0-0,-,-,0x0,S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,3,NtLmSsp,NTLM,SRV01,{00000000-0000-0000-0000-000000000000},-,NTLM V1,128,0x0,-,192.168.1.3,36878)|Security|An account was successfully logged on.Subject:Security ID: S-1-0-0 Account Name: - Account Domain: - Logon ID: 0x0Logon Type: 3New Logon: Security ID: S-1-5-21-2692671718-3285579559-3264406991-1000 Account Name: MAVENSI8 Account Domain: MAVENSI8-PC Logon ID: 0x2e9030 Logon GUID: {00000000-0000-0000-0000-000000000000}Process Information: Process ID: 0x0 Process Name: -Network Information: Workstation Name: SRV01 Source Network Address: 192.168.1.3 Source Port: 36878Detailed Authentication Information: Logon Process: NtLmSsp Authentication Package: NTLM Transited Services: - Package Name (NTLM only): NTLM V1 Key Length: 128This event is generated when a logon session is created. It is generated on the computer that was accessed.The subject fields indicate the account on the local system which requested the logon. This is most commonly a service such as the Server service, or a local process such as Winlogon.exe or Services.exe.The logon type field indicates the kind of logon that occurred. The most common types are 2 (interactive) and 3 (network).The New Logon fields indicate the account for whom the new logon was created, i.e. the account that was logged on.The network fields indicate where a remote logon request originated. Workstation name is not always available and may be left blank in some cases.The authentication information fields provide detailed information about this specific logon request. - Logon GUID is a unique identifier that can be used to correlate this event with a KDC event. - Transited services indicate which intermediate services have participated in this logon request. - Package name indicates which sub-protocol was used among the NTLM protocols. - Key length indicates the length of the generated session key. This will be 0 if no session key was requested.|46031|Microsoft-Windows-Security-Auditing|20140605041823.673410-000|20140605041823.673410-000|Audit Success|(null)
12548|Special Logon|MAVENSI8-PC|NULL|4672|4672|4|(S-1-5-21-2692671718-3285579559-3264406991-1000,MAVENSI8,MAVENSI8-PC,0x2e9030,SeImpersonatePrivilege
我想要这种格式化的输出......
请,任何人帮助我。
提前致谢。
答案 0 :(得分:0)
忘记正则表达式,只需迭代它。
BufferedReader in = new BufferedReader(new FileReader("file.txt"));
String line;
List<String> lines = new ArrayList<String>();
while ((line = in.readLine()) != null) {
line = line.replaceAll("\t", "");
line = line.replaceAll("\n", "");
line = line.replaceAll(" ", "");
lines.add(line);
}
答案 1 :(得分:0)
尝试使用替换功能。
String str = " \n a b c \n 1 2 3 \n x y z ";
str = str.trim().replaceAll("\n ", "");
希望这能解决你的问题。
答案 2 :(得分:0)
如果你真的想删除换行符,制表符和空格,那么正则表达式会非常简单:
\s+
但实际上你想在单词之间留一些空格。
要做到这一点,在仍然删除行的开头和结尾处的空格时,您可以使用:
[ ]*[\r\n\t]+[ ]*
要在Java正则表达式中替换,例如:
String your_result_string = your_original_string.replaceAll("[ ]*[\r\n\t]+[ ]*", "");
解释正则表达式:
[ ]* # any character of: ' ' (0 or more times)
[\r\n\t]+ # any character of: '\r' (carriage return),
# '\n' (newline), '\t' (tab) (1 or more
# times)
[ ]* # any character of: ' ' (0 or more times)
答案 3 :(得分:0)
试试这个
String unformattedText = FileUtils.readFileToString(new File(
"test.txt"));
String[] splittedText = unformattedText.split("\\n\\d");
for (String split : splittedText) {
System.out.println(split.replaceAll("\\n","").replaceAll("\\s", ""));
}
将Apache Commons IO FileUtils用于与IO /文件相关的内容
输出:正是您需要的