script using grep to filter 10 tar files
I have to make a script using grep filtering a pattern in a 10 files that have been compressed tar format, this is what I have done until now.
#!/bin/sh cd ../Data ls *.tar #list file with extention tar tar – xzvf *.tar > ../Result/file01.tar #decompress tar file and send to directory Result as file01.tar for i = 1; $i <=10; $i=++; #for i as the first file until the 10 th file find a pattern from tar files in Data and send to Result directory as fileresult.out do grep “pattern” Data/*.tar > Result/fileresult.out echo “\n” done Also I have to improve this script #!/bin/sh # ../Data/subject01.fa ../Data/query01.fa ../Data/subject02.fa ../Data/query02.fa cd ../Data formatdb -i subject01.fa -p F formatdb -i subject02.fa -p F cd ../Code blastall -p blastn -d $1 -i $2 -F F -e 1e-5 -o ../Results/blast01.raw -m 9 blastall -p blastn -d $3 -i $4 -F F -e 1e-5 -o ../Results/blast02.raw -m 9 for i in ../Results/b*.raw; do echo $i >> ../Results/filtro100.out grep 100.00 $i >> ../Results/filtro100.out echo "\n" >> ../Results/filtro100.out done I modified as: #!/bin/sh # ../Data/subject01.fa ../Data/query01.fa ../Data/subject02.fa ../Data/query02.fa cd ../Data formatdb -i subject01.fa -p F -i subject02.fa -p F cd ../Code blastall -p blastn -d ../Data/subject01.fa -i ../Data/query01.fa -d ../Data/subject02.fa -i ../Data/query02.fa -F F -e 1e-5 -o ../Results/blast01.raw -m 9 ../Results/blast02.raw -m 9 #without blast02.raw it run as only blast01.raw #blastall -p blastn -d -F F -e 1e-5 -o ../Results/blast02.raw -m 9 cat ../Results/blast01.raw ../Results/blast02.raw > ../Results/prueba.raw for i in ../Results/p*.raw; do echo $i >> ../Results/filtro100.out grep 100.00 $i >> ../Results/filtro100.out echo "\n" >> ../Results/filtro100.out done when I run this script come out this error [blastall] ERROR: Arguments must start with '-' (the offending argument #19 was: '../Results/blast02.raw') as I what to incluide not only filter 100 I change the last part as do echo $i >> ../Results/filtro100.out grep ["$i" -le 100.00] || ["$i" -ge 90.00] $i >> ../Results/filtro100.out echo "\n" >> ../Results/filtro100.out done but is send an error, how I can to fix this and it is something that I can improve of this script Thanks you for the help |
Quote:
|
In addition, tar is not a compression tool; it just collects all input into one big file archive.
If you created with with the z (gzip) or j (bzip2) flag, then it will be compressed as well. If the archive is compressed, you will need to uncompress it first. |
What you've done so far and let's know if you're stuck somewhere. Following would be helpful for you:
http://tldp.org/LDP/abs/html/ http://linux.die.net/man/1/tar http://linux.die.net/man/1/gzip |
Quote:
as stated post what you have done, we will be glad to help you fix your errors, but not do you homework for you as that is against forum rules. |
Quote:
|
Quote:
Here's some BASH scripting guides should you need them: http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.gnu.org/software/bash/man...ode/index.html http://www.grymoire.com/Unix/Sh.html http://www.tldp.org/LDP/abs/html/ http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls *Note the Advanced BASH Scripting Guide is not the first link to read (and for good reasons). |
grep a patter in 10 file comprised in a tar file
I made this script
#!/bin/sh cd ../Data_taller_eval/Data_preg2.tar #list file with extention tar tar –xzvf Data_preg2.tar > ../Result_taller_eval #decompress tar file and send to directory Result as file01.tar #for (my $i=1;$i<=10;$i++;) #for i as the first tar file until the 10 th file find a pattern from tar files Data and send to Result directory fileresult.out #do #grep “agcct” Data/*.sh > Result/fileresult.out #echo “\n” #done I try to run the first part but I get this error tar: opción incorrecta -- «�» Intente`tar --help' o `tar --usage' para mayor información. I when to man tar but I do not what to do when I run all the script give me an error ./scriptgrep.sh: 10: Syntax error: Bad for loop variable How I make an good for loop variable Thanks you for your help |
Fisrt thing is to add debug mode i.e. set -xv in your script and check that where scripts stuck.
Second, in order to check content of a tar file, use -t flag, as: Code:
~$ tar -tvf foo.tar However, you can grep a pattern simply, as: Code:
~$ cd ../Data_taller_eval/ |
Thanks you for your answer I did as
#!/bin/sh set -xv cd ../Data_taller_eval/ grep "agcct" <(tar -tvf Data_preg2.tar) #list file with extention tar #tar –xzvf Data_preg2.tar > ../Result_taller_eval #decompress tar file and send to directory Result as file01.tar #for (my $i=1;$i<=10;$i++;) #for i as the first tar file until the 10 th file find a pattern from tar files Data and send to Result directory fileresult.out #do #grep “agcct” Data/*.sh > Result/fileresult.out #echo “\n” #done and the answer is cd ../Data_taller_eval/ + cd ../Data_taller_eval/ grep "agcct" <(tar -tvf Data_preg2.tar) #list file with extention tar ./scriptgrep.sh: 8: Syntax error: "(" unexpected I do not recognized what is the syntax error and how I make this with 10 file the last part I used for (my $i=1;$i<=10;$i++;) but it also get error Thanks you |
Use /bin/bash instead of /bin/sh.
You can also try like: Code:
#!/bin/bash |
Thanks, I try to run this
#!/bin/bash set -xv cd ../Data_taller_eval/ while read -r file do grep 'agcct' $file done < $(tar -tvf Data_preg2.tar) and I get this cd ../Data_taller_eval/ + cd ../Data_taller_eval/ while read -r file do grep 'agcct' $file done < $(tar -tvf Data_preg2.tar) tar -tvf Data_preg2.tar) tar -tvf Data_preg2.tar ++ tar -tvf Data_preg2.tar tar: Data_preg2.tar: No se puede read: Es un directorio tar: Al principio de la cinta, se terminará ahora tar: Error is not recoverable: exiting now tar -tvf Data_preg2.tar) tar -tvf Data_preg2.tar ++ tar -tvf Data_preg2.tar tar: Data_preg2.tar: No se puede read: Es un directorio tar: Al principio de la cinta, se terminará ahora tar: Error is not recoverable: exiting now ./scriptgrep1.sh: línea 11: $(tar -tvf Data_preg2.tar): redireccionamiento ambiguo line 11 is ambiguos and how I can to make this to 10 file ? |
Just try it now:
Code:
#!/bin/bash |
All times are GMT -5. The time now is 05:30 PM. |