2016-12-08 58 views
0

對不起,問一個簡單的問題,我有一個文本文件名爲文件1與很多行大多是句子。我想用空格作爲分隔符來分隔這些行,並將這些字符串作爲每行1個打印到名爲的另一個文件file2我該如何在UNIX中執行此操作?下面給出轉換文件的多行文件每行單個字符串

文件1看起來內容:

文件1

build targets target1 , target2, target3 in both windows machines 
please rebuild target 4 build target5 as well as target6 
target1 abc/saddggav/aafvfaddf/adfbdafdb/text1.msg 
target2 dfdfbd/afbdahgtngs/adbadfdsbsdb/snstnhdb/text2.msg 
target2 
target6 
please take all the files from dsvdfdfv/afedfgbadvbath/dsfbdsgfabadbafd/sdfbdgnsdb/dsfbwsgdb 
please rebuild "build target4 and build target6 on sun machines 

我想排除之間的所有路徑,但必須採取目標在該行的開頭並將所有單詞作爲每1行1個字符串打印到另一個文件file2

有人可以幫我解決這個問題嗎?

+0

你似乎可以用'cat a.txt | tr''\ 012> b.txt' – Marichyasana

+0

謝謝Marichyasana –

+0

我試過貓a.txt | tr''\ 012> b.txt這個命令,這是在字符串之間的空格加上0 –

回答

0
input.txt: 
build targets target1 , target2, target3 in both windows machines 
please rebuild target 4 build target5 as well as target6 
target1 abc/saddggav/aafvfaddf/adfbdafdb/text1.msg 
target2 dfdfbd/afbdahgtngs/adbadfdsbsdb/snstnhdb/text2.msg 
target2 
target6 
please take all the files from dsvdfdfv/afedfgbadvbath/dsfbdsgfabadbafd/sdfbdgnsdb/dsfbwsgdb 
please rebuild "build target4 and build target6 on sun machines 

Code: cat input.txt | tr " " "\n" > output.txt 

Output.txt: 
build 
targets 
target1 
, 
target2, 
target3 
in 
both 
windows 
machines 
please 
rebuild 
target 
4 
build 
target5 
as 
well 
as 
target6 
target1 
abc/saddggav/aafvfaddf/adfbdafdb/text1.msg 
target2 
dfdfbd/afbdahgtngs/adbadfdsbsdb/snstnhdb/text2.msg 
target2 
target6 
please 
take 
all 
the 
files 
from 
dsvdfdfv/afedfgbadvbath/dsfbdsgfabadbafd/sdfbdgnsdb/dsfbwsgdb 
please 
rebuild 
"build 
target4 
and 
build 
target6 
on 
sun 
machines 
相關問題