grep: match all characters up to (not including) first blank space

前端 未结 4 787
南旧
南旧 2021-02-05 04:24

I have a text file that has the following format:

characters(that I want to keep) (space) characters(that I want to remove)

So for example:

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 05:12

    Following up on the answer by @Steve, if you want to use a different separator (eg. comma), you can specify it using -F. This will be useful if you want the content of each line upto the first comma, such as when trying to read the value of the first field in a csv file.

    $ awk -F "," '{print $1}' text1.txt > text2.txt
    

提交回复
热议问题