You should provide feedback to people that invest time in your question or people will just start ignoring your posts.
Hi
I have a script which modifies a .txt file
awk 'BEGIN{FS=OFS="\t"}{split($1,a,"_"); split(a[3],b,"/"); print a[1],a[2],b[1],b[2],$0}' file.txt | awk 'BEGIN{FS=OFS="\t"}{split($18,a,";"); split(a[2],b,"="); print b[2],$0}' > out_file.txt
I have a bunch of .txt files in a folder
I want to run this script on my files and write the output file by the name of the original file
I have tried this but nothing happening
> for i in `find . -maxdepth 1 -type f -iname "*.txt" awk 'BEGIN{FS=OFS="\t"}{split($1,a,"_"); split(a[3],b,"/"); print a[1],a[2],b[1],b[2],$0}'| awk 'BEGIN{FS=OFS="\t"}{split($18,a,";"); split(a[2],b,"="); print b[2],$0}'print > out}' *.txt
-bash: syntax error near unexpected token `|'
(base) user112$
Any help to achieve this?
1 answer
for i in *.txt; do
awk 'BEGIN{FS=OFS="\t"}{split($1,a,"_"); split(a[3],b,"/"); print a[1],a[2],b[1],b[2],$0}' $i | awk 'BEGIN{FS=OFS="\t"}{split($18,a,";"); split(a[2],b,"="); print b[2],$0}' > $i'_1'.txt
done
Sorry I did not provide feedback because I don't understand this things and I provided the code from a bioinformatician in our department for future of somebody like me was faced the same problem
Do you realize that the code by itself holds no value, because your question is not clear and what the answer does is super confusing?
Ideally, if you add your own answer, explain what it does in detail. You're treating the site like it's a personal repository of your code snippets, which it is not.
Log in to answer this question.
Try giving
awkthe-F(input field separator argument) - tab or space or comma or whatever it is. Try that for one of the files.Also your
echo | awkthing can be achieved usings=$(basename $i .txt)if you just wish to prune the.txt.you seem to be wrinting everything into out. im not good with bashs quoting rules, so to be safe:
for i in $(find ..); do awk 'cmd' $f > ${f}_out.txt ; done
This is a rather complicated statement and you should create a script from it that you can (re)use in a loop and reuse it. Saves time in the end.