Reputation: 11
I have a couple of files which have a format of something like this:
TCTCTGGAAAGGGACGCCTGGGAGG 10 AAAAATACATTCTAACCTCGGCGT 1 TAATTTCATCAATATATCAATG 1 (etc...)
I want to remove everything after the space so that I only get this in the end:
TCTCTGGAAAGGGACGCCTGGGAGG AAAAATACATTCTAACCTCGGCGT TAATTTCATCAATATATCAATG (etc...)
How would I do this?
Upvotes: 1
Views: 1729
Reputation: 690
Not as concise and pretty as timos's answer :), but another quick example of the same functionality but written in Ruby.
#!/usr/bin/env ruby
data = File.read("data.txt")
f = File.open("outData.txt", "w")
finalData = data.scan(/^\w+/)
finalData.each {|i| f.write(i + "\n")}
f.close
Upvotes: 0
Reputation: 340903
cut -d' ' -f1 file.txt
or:
sed 's/ .*//' file.txt
or
sed -e 's/[^ACTG]//g' file.txt
or
awk '{print $1}' file.txt
Upvotes: 2