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
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 06:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy