Reputation: 1
Sorry to ask a simple question, i have a text file named file1 with a lot of lines mostly sentences. I want to separate the lines with space as separator and print those strings as 1 per line into another file called file2 how can i do this in UNIX?
The contents of file1 looks as given below:
file1
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
I want to exclude all the paths in between but has to take the target in the beginning of the line and print all the words as 1 string per 1 line into another file file2.
Could some one please help me with this?
Upvotes: 0
Views: 69
Reputation: 11
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
Upvotes: 1