Sponsored Content
Top Forums Shell Programming and Scripting While loop with input in a bash script Post 302957380 by faizlo on Saturday 10th of October 2015 12:52:02 AM
Old 10-10-2015
bash, tr, awk, sed

This is my master.sh script:
Code:
#!/bin/bash                                                                                             
#check to see if there is an input file:                                                                
if [ "$#" -lt 1 ]
then
  echo "Usage: $0 input_file ..."
  exit 1
fi

#Check if the file is empty or not                                                                      
file=$1
if [[ -s $1 ]]                   # if not empty:
then
  echo ""
  echo "**** $file has data."
  cat $1 | sed 's/>/\n>/g' > temp1.txt
  cat temp1.txt | sed '/^>/ d' > temp2.txt
  awk '!NF{if(++n <=1) print; next}; {n=0; print}' < temp2.txt > dna.out
  awk '/./{printf "%s",$0;next} {print "\n";} END{if (/./)print""}' dna.out > DNA.out
  echo "**** Number of DNA sequences:"
  grep -cve '^\s*$' DNA.out
  echo "**** Mumber of empty lines:"
  grep -ce '^\s*$' DNA.out
  echo ""
  #Remove duplicate empty lines:                                                                        
  awk '!NF{if(++n <=1) print; next}; {n=0; print}' < temp2.txt > DNA.out                               
  echo "**** DNA.out created (removed FASTA header)"
  #convert to mRNA and remove temp1, temp2 to avoid confusion                                           
  tr ACGT ACGU < DNA.out > RNA.out
  echo "**** RNA.out created (T -> U)"
  echo ""
  rm temp1.txt temp2.txt
  moved to conversion:                                                                                
  while read rna; do                                                                                  
      aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)                          
      echo "$aawork" | sed 's/ //g'                                                                   
      echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/[ ]*\([0-9]*\) \(.*\)/\2\
: \1/'                                                                                                  
  done                                                                                                
  echo "**** creating AminoAcid from DNA:"
  ./convert_dna.sh < DNA.out > DNA_AminoAcid.out
  echo "**** Amino Acids from DNA saved in DAN_AminoAcid.out."
  echo "**** creating AminoAcid from RNA:"
  ./convert_rna.sh < RNA.out > RNA_AminoAcid.out
  echo "**** Amino Acids from RNA saved in RAN_AminoAcid.out."
  echo ""

else    # if the file is empty.                                                                         
  echo "**** $1 has no data, or file does not exist."
  echo "**** done!"
  echo ""
#clean the FASTA file and remove all lines starting with >, adding a new line first to avoid mixing all DNA samples:                                                                                           
fi;

convert_dna.sh and convert_rna.sh are two scripts that contain the while loop I mentioned in my first post. One with dna.sed and the other with rna.sed.

My question is how to add the while loop two times one with the dna.sed and the other one with rna.sed.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

2. Shell Programming and Scripting

Input file to bash script

Hi, I have this script Script.sh: #!/bin/sh sed 's,\,,g' input.dat > output .dat But i want to run it witb different files. So i want the input file as an input argument to the script, how could i do that. Running it like this: > Script.sh input.dat (2 Replies)
Discussion started by: Johanni
2 Replies

3. Shell Programming and Scripting

Bash Script for parse input like option and value

I would create a bash script than parse like this: test.sh -p (protocol) -i (address) -d (directory) I need retrive the value after -p for example... understand??? I hope... thanks (6 Replies)
Discussion started by: ionral
6 Replies

4. Shell Programming and Scripting

Detail on For loop for multiple file input and bash variable usage

Dear mentors, I just need little explanation regarding for loop to give input to awk script for file in `ls *.txt |sort -t"_" -k2n,2`; do awk script $file done which sorts file in order, and will input one after another file in order to awk script suppose if I have to input 2 or... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

5. UNIX for Dummies Questions & Answers

Feed Input to a script running on bash

Hi Sir, I am just learning bash scripting and I came across a challenge. I need to input F11 to a script among many text inputs. For all the text inputs i did following. # sh test.sh < input.txt where input.txt contains all the text inputs in new lines. This worked fine until i... (1 Reply)
Discussion started by: gaurav kumar
1 Replies

6. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

7. Shell Programming and Scripting

Bash loop hording keypress input

I have a bash loop that waits for a single key press, then does $something depending on what $key is pressed before refreshing the screen with updated data. The problem I have is that the script will store additional key presses and chain them together causing the screen to redraw and the script... (1 Reply)
Discussion started by: DarkPhoenix
1 Replies

8. Shell Programming and Scripting

Bash shell script with mandatory and optional input

Hello I would like to write a bash shell script which will need user to supply one variable which is mandatory and some other optional variables. If mandatory variable is not supplied by user, the script will exit. If optional values are not supplied by user, hard-coded value (in the script)... (3 Replies)
Discussion started by: atanubanerji
3 Replies

9. Shell Programming and Scripting

Help in input file's in bash script

hello guys i have bash script to open my routers with username and password i made script but i have problem this script can/t read password from file #!/bin/bash router_file="ips" passwd="password.txt" for router in cat ;$router_file do for pass in cat ;$passwd; do res=$(curl -m 1 ... (7 Replies)
Discussion started by: manhoud
7 Replies

10. Shell Programming and Scripting

Input redirection within bash script

Hi, when I try to redirect input and the command is described as a string within an array redirection does not work. why? #!/bin/bash dir=("tail < ./hello.txt") tail < ./hello.txt #works ${dir} #does not work (2 Replies)
Discussion started by: heinzel
2 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 10:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy