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?
Try giving
awk
the-F
(input field separator argument) - tab or space or comma or whatever it is. Try that for one of the files.Also your
echo | awk
thing 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.