删除特定模式后的其余行

时间:2018-10-10 11:27:17

标签: awk

该示例中的目的是在找到模式90000:之后删除每行的其余字符串

输入文件

import React, { Component } from 'react';
import './App.css';

import MeetingMode from'./MeetingMode';
import NavbarMenu from './Navbar';
import Popup from "reactjs-popup";
import axios from 'axios';
import {withRouter, history, Redirect, Route} from "react-router";

 class MeetingModeLoad extends Component{
    constructor(props)
    {
        super(props);
        this.state ={
            meeting:{},
            value:0
        };
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
    }
    async handleSubmit(event) 
    {
        event.preventDefault();
        let meetingLoadCode = this.state.value
        try{
        let getter = await axios.get(`https://smartnote1.azurewebsites.net/api/meetings/${meetingLoadCode}`)
        let meetingLocal = getter.data
        this.setState({meeting:meetingLocal})
        if(meetingLocal.Status == 2)
        {
            console.log("please join meeting that is planned or under going")
        }
        else
        {
            console.log("/meetingMode/" + this.state.meeting.MeetingID);
            this.props.history.push("/meetingMode/" + this.state.meeting.MeetingID)
        }
        }
        catch(error)
        {
            console.error(error)
        }
    }

    handleChange(event) 
    {
        this.state.value = event.target.value
        console.log(this.state.value)
    }
render()
{
    return(            
            <div>
                <Popup
                    trigger={<button className="meetingModeButton" onClick={() => this.handleClick}>Meeting Mode</button>}
                    modal
                    closeOnDocumentClick>
                        <div className="newNote">
                            <header style={{background: "#F7941D" }}> Meeting Mode</header>
                            <form onSubmit={this.handleSubmit}>
                            <label> Enter Meeting Code : 
                                <input type="text" name="type" className="inputBox"  onChange={this.handleChange}/>
                            </label>
                            <input type="submit" value="Submit" />
                            </form>
                        </div>
                        {console.log(this.state.meeting)}
                </Popup>  
            </div>
    )
}
}
export default withRouter (MeetingModeLoad)

我尝试了。该代码仅删除文本的一部分。目的是在找到90000后删除所有字符:

generation
122344
41572:47149-47999/2(14485-14910) 41584:47149-47999/2(14911-15449) 90000:47919-47999/2(15447-15477) 90002:47919-47999/2(15478-15418) 
41548:48094-48894/2(12844-14244) 41590:48094-48894/2(14244-14944) 41572:48094-48894/2(14945-14045) 41584:48094-48894/2(14049-14449) 90000:48094-48114/2(14447-14447) 90002:48094-48114/2(14448-14458) 
12345

所需的输出

sed 's/90000:*//' file

感谢您的支持

1 个答案:

答案 0 :(得分:2)

请您尝试以下。

awk '{gsub(/ 9000.*/,"")} 1'  Input_file

要修复您的代码,请尝试:

sed 's/90000:.*//'  Input_file