Adding .txt or .fa extension to UnixExecutable
1
0
Entering edit mode
7.5 years ago
NGS-Newbie ▴ 20

Hi All

How can I add .txt or .fa extension to multiple 'Unix Executable' sequence files using terminal?

Thanks!

Adding extension to UnixExecutable • 3.0k views
ADD COMMENT
1
Entering edit mode

How can I add .txt or .fa extension to multiple 'Unix Executable' sequence files

you don't because you don't understand what you're doing :-)

please show us a example of input/output.

ADD REPLY
1
Entering edit mode

Can you be a little clearer about what you want to do and why?

A binary file is compiled byte code. It will always be interpreted as byte code regardless of what extension you put on it. Extensions really don't mean that much in linux, and that's especially the case for bash and sh.

If what you want to do is simply rename a file you can:

$ rename 's/$/.txt/g' filename

But I'm still not clear on why.

ADD REPLY
0
Entering edit mode

Hi mforde84 and Pierre

I split one single file FASTA file with 100 reads (a subset from 75000+ reads; post merging and QC) into one hundred separate files, with one sequence each using faSplit. However, I could not give an extension to the one hundred split files, in absence of which on my mac they were visible as Unix Executable files. But the following, posted below, worked!

Thank you.

ADD REPLY
0
Entering edit mode
7.5 years ago
NGS-Newbie ▴ 20

Thank you all!

The following worked -

for i in *; do mv "$i" "$i.txt"; done

It's from here - http://osxdaily.com/2012/11/22/add-file-extension-group-of-files-os-x/

ADD COMMENT
0
Entering edit mode

For reference, a more "Unixy" solution imo:

find ./ -maxdepth 1 -type f -exec mv {} {}.txt \;

ADD REPLY
1
Entering edit mode

the for loop is POSIX compliant. if by unixy you mean meaninglessly verbose with no added benefit to readability or speed, then i must respectfully disagree :) i mean why not:

find ./ -maxdepth 1 -type f | xargs -n -P "$(grep -c ^processor /proc/cpuinfo)" -iFILES sh -c 'mv FILES FILES.txt'

instead of:

rename 's/$/.txt/g' ./*

It took me a 10s longer to write the first one, even if it's 0.001ms faster than rename. :D

ADD REPLY
0
Entering edit mode

How is it needlessly verbose? That's why I said "in my opinion", because I find the find (heh) – and even the xargs – solutions more intuitive and, frankly, faster to type. i.e. I'm too good with Unix that it wouldn't take me 10 more seconds to come up with and execute you're exaggerated "verbose" example over the rename one. :D

ADD REPLY
0
Entering edit mode

In addition for i in * will fail if there are too many files.

However,

for i in $(find ./ -maxdepth 1 -type f); do mv "$i" "$i".txt; done

Should do it :)

ADD REPLY
0
Entering edit mode

This doesn't look right - can you check the quotes please?

ADD REPLY
0
Entering edit mode

Oops. Done. More characters.

ADD REPLY
0
Entering edit mode

novice & mforde84

We could keep discussing the best way to do this, but as long as they work, it's no big deal. For example, I use xargs and not -exec because of the -I option which gives me a lot more freedom to work with different types of values passed on by find, but I don't say it is objectively better, just that it works for me.

ADD REPLY

Login before adding your answer.

Traffic: 2547 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6