我有一个像这样的50k行的文本文件
word1 1 23 word2 43 23 word3 197 word4并需要一种方法使它看起来像这样:
word1 word2 word3 word4所以我需要一种方法来删除每行中第一个空格后面的每个字符。 我该怎么做呢?
I have a text file with 50k lines like this
word1 1 23 word2 43 23 word3 197 word4and need a way to make it look like this:
word1 word2 word3 word4So I need a way to remove every character behind the first space in each line. How do I do this?
最满意答案
多种解决方案
解决方案1:Vim
在vim中打开文件,然后运行:
:%s/\s.*//g
解决方案2:sed
sed "s/ .*//g" < input_file > output_file
在Windows上不能这样做。
解决方案3:Excel / Calc / Numbers
在OpenOffice / MSOffice / etc中导入文件。 您可以将空间设置为分隔符。 但这是一个更慢,更少的乐趣。 :)
Multiple solutions.
Solution 1: Vim
Open the file in vim, then run:
:%s/\s.*//g
Solution 2: sed
sed "s/ .*//g" < input_file > output_file
Cannot do this on windows tho.
Solution 3: Excel/Calc/Numbers
Import the file in OpenOffice/MSOffice/etc. You can set space as a delimiter. But this is a slower and less fun. :)
更多推荐
发布评论