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
http://milospjanic.blogspot.com/2014/07/how-to-select-two-or-more-columns-from.html
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\*)
do
awk -v OFS="\t" '$1=$1' "$f"> "$f"_tabseparated;
done

No comments:

Post a Comment