我需要从开头的每一行中删除时间戳记详细信息。我该如何实现?
我尝试使用
regex = "[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,4} [0-9]{1,2}:[0-9]{1,2}:[0-9]
{1,2}):[0-9]{1,3}"
我的方法就像
$Check = (Get-Content -Path .\file.txt|Select-Object -last 3|Out-String)
$Check = $Check -replace('$regex','')
文本file.txt中的行类似于:
[06/13/19 08:52:58] The new world
[06/13/19 08:52:58] Computing
[06/13/19 08:52:58] Technology
答案 0 :(得分:2)
和另一种方法是使用-split
字符串运算符,并在]
上分割[即括号和空格]。像这样的东西
('[06/13/19 08:52:58] The new world' -split '] ')[1].Trim()
output = The new world
答案 1 :(得分:1)
如果它是静态图章,请使用子字符串。
import React, { Component } from 'react';
import { Button, Text, View, StyleSheet } from 'react-native';
import { Constants, WebBrowser } from 'expo';
export default class App extends Component {
state = {
result: null,
};
render() {
return (
<View>
<Button
title="Open WebBrowser"
onPress={this._handlePressButtonAsync}
/>
<Text>{this.state.result && JSON.stringify(this.state.result)}</Text>
</View>
);
}
_handlePressButtonAsync = async () => {
let result = await WebBrowser.openBrowserAsync('https://expo.io');
this.setState({ result });
};
}
例如,这仅是时间戳记。
在您的情况下:
$start = Get-Content -Path C:\Windows\Panther\setupact.log -First 1
$start.Substring(11,8)
这将其删除。
希望有帮助! BR
编辑(请参阅评论):
$start = "[06/13/19 08:52:58] Technology"
$start.Substring(20)