I have sequences of the genetic code like this: ACTGgcttaTGCA and I'm trying to figure out the Unix commands to remove lowercase characters only, so that the string then appears as ACTGTGCA (gctta removed).

Can anyone offer any advice as to the appropriate means to do this? The files are too large to open in a text editor therefore I can't simply do 'find and replace'.

  • Which Unix are you talking about? "Unix" is a family name that covers lots of different implementations; if you tell us which one you are interested in, we can give you answers tailored to your situation. Also, this may receive more attention if migrated to Unix & Linux instead; if you want your question migrated, "flag" it for moderator attention. – a CVn Nov 4 '16 at 10:42
sed 's/[a-z]//g' yourfile >> newfile

If you want to edit the file in-place:

sed -i 's/[a-z]//g' yourfile

Surely you can just find and replace, you just need to do it on the stream rather than then loading the whole file. Usually you'd use the tool sed for this. This could look like the following:

sed -r 's/[a-z]*//g' input.txt

This would match any sequence of lowercase characters and replace them with nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.