Thursday, July 17, 2014

How to change spaces to tabs in multiple files simultaneously

If you have created bed files by cutting it from a file using awk as in this post
it may be that columns are separated by spaces, which will cause bedtools unable to read files.

If you want to convert spaces to tabs you can copy those files that have been cut from the original bed files to a new folder and run a code:

for filename in *; do awk -v OFS="\t" '$1=$1' ${filename} > ${filename}_tabseparated; done

Alternatively, to do this with in the original folder, i.e. to select *bb.bed.cut files within the original folder and to perform the change with the awk command run the following code:

for f in $(find . -name \*bb.bed.cut\*)
awk -v OFS="\t" '$1=$1' "$f"> "$f"_tabseparated;

No comments:

Post a Comment