Shell Scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting
# 8  
Old 10-24-2010
Oops... true !
I always mix those <() $() "" and `` just let's try them all...
One will work LoL 8)
# 9  
Old 10-24-2010
Code:
awk '
function s(a) {gsub(/[a-zA-Z()]/,"",a);return a}
/^Initial dG/ {init=$NF;t=1} 
/^Multi-loop/ { m=(m=="")?X s($(NF-1)$NF):m RS s($(NF-1)$NF)}
/^Hairpin loop/ {h=(h=="")?X s($(NF-1)$NF):h RS s($(NF-1)$NF)}
/^Structure/&&t==1 {printf "%s\nHairpin loop:\n%s\nMulti-loop:\n%s\n\n",init,h,m ; init=m=h="";t=0}
END {printf "%s\nHairpin loop:\n%s\nMulti-loop:\n%s\n",init,h,m }
' infile

-25.40
Hairpin loop:
102-110
65-71
Multi-loop:
37-115

-25.10
Hairpin loop:
79-85
Multi-loop:
37-93

# 10  
Old 11-05-2010
Shell scripting

I made corrections in the program as you suggested. It giving the output like this; It is not printing the dg number for all structures and Hairpin loop heading from the second structure.

Output given from the corrections:
Code:
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
Multi-loop:
37-93
79-85

Actual output :
Code:
-25.40

Multi-loop:
37-115
Hairpin loop:
102-110
65-71

-25.10

Multi-loop:
37-93
Hairpin loop:
79-85

Quote:
Originally Posted by frans
what can be tried is to remove all spaces in the A and check for string without spaces with following changes :

Remove the quotes around $A:

line 05: case "$A" in to be replaced by case $A in

and in the 3 case statements:

line 06: "Initial dG ") to be replaced by Initial*)

line 10: "Hairpin loop") to be replaced by Hairpin*)

line 15: "Multi-loop") to be replaced by Multi-loop)

Don't forget to put the * in the first two ones

Last edited by Scott; 11-06-2010 at 08:56 AM.. Reason: Use code tags, please...
# 11  
Old 11-05-2010
I saved the code, and this one is working by me (with your sample)

bash code:
  1. #!/bin/bash
  2. PrintVal()  { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
  3. while IFS=':=' read A B C
  4. do
  5.    case $A in
  6.       Initial*)
  7.          echo -e "\n\n$B\n"
  8.          Hairpins=0
  9.       ;;
  10.       Hairpin*)
  11.          ((Hairpins==0)) && echo "$A:"
  12.          PrintVal
  13.          ((Hairpins++))
  14.       ;;
  15.       Multi-loop)
  16.          echo "$A:"
  17.          PrintVal
  18.       ;;
  19.    esac
  20. done <$INFILE
Gives the output:
Code:
 -25.40

Multi-loop:
37-115
Hairpin loop:
102-110
65-71


 -25.10

Multi-loop:
37-93
Hairpin loop:
79-85

# 12  
Old 11-05-2010
Shell scripting

I made corrections in the program as you suggested. It giving the output like this; It is not printing the dg number for all structures and Hairpin loop heading from the second structure.

Output given from the corrections:
Code:
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
Multi-loop:
37-93
79-85

Actual output :
Code:
-25.40

Multi-loop:
37-115
Hairpin loop:
102-110
65-71

-25.10

Multi-loop:
37-93
Hairpin loop:
79-85

Quote:
Originally Posted by frans
I saved the code, and this one is working by me (with your sample)

bash code:
  1. #!/bin/bash
  2. PrintVal() { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
  3. while IFS=':=' read A B C
  4. do
  5. case $A in
  6. Initial*)
  7. echo -e "\n\n$B\n"
  8. Hairpins=0
  9. ;;
  10. Hairpin*)
  11. ((Hairpins==0)) && echo "$A:"
  12. PrintVal
  13. ((Hairpins++))
  14. ;;
  15. Multi-loop)
  16. echo "$A:"
  17. PrintVal
  18. ;;
  19. esac
  20. done <$INFILE
Gives the output:
Code:
 -25.40
 
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
 
 
 -25.10
 
Multi-loop:
37-93
Hairpin loop:
79-85


Last edited by Scott; 11-06-2010 at 08:59 AM.. Reason: Code tags
# 13  
Old 11-05-2010
What's the output of this:
bash code:
  1. #!/bin/bash
  2. while IFS=':=' read A B C
  3. do
  4.    echo "A='$A' B='$B' C='$C'"
  5. done <$INFILE

---------- Post updated at 23:06 ---------- Previous update was at 21:52 ----------

Problem with leading and trailing tabs and spaces, to get rid of them, replace in line 5.
Code:
case $A in

by
Code:
case $(echo $A) in

This User Gave Thanks to frans For This Post:
# 14  
Old 11-05-2010
Shell scripting

I made modification as 'case $(echo $A) in' in script. Output is ok except '-e'. -e has to be removed. It is coming before every dG number i.e., -25.40, -25.10, etc. How it is coming I am in confusion. Thanks in advance.
Code:
-e 
-25.40
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
12-17
-e 
-25.10
Multi-loop:
37-93
Hairpin loop:
79-85
57-62
-e 
-24.80
Multi-loop:
37-115
Hairpin loop:
102-110
65-71
5-10

Quote:
Originally Posted by frans
What's the output of this:
bash code:
  1. #!/bin/bash
  2. while IFS=':=' read A B C
  3. do
  4. echo "A='$A' B='$B' C='$C'"
  5. done <$INFILE

---------- Post updated at 23:06 ---------- Previous update was at 21:52 ----------

Problem with leading and trailing tabs and spaces, to get rid of them, replace in line 5.
Code:
case $A in

by
Code:
case $(echo $A) in


Last edited by Scott; 11-06-2010 at 08:59 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

help me in Shell Scripting

Hi there please have a look at the code..i want to create Using a named pipe. Run a find in the background starting in the working directory While this is happening wait for input from the user to ask him which file to find. If the user does not enter any data in 10 seconds ask the user again.... (1 Reply)
Discussion started by: kattak1511
1 Replies

3. Shell Programming and Scripting

Shell scripting

Hi, if in a network there are lots of PCs connected with either windows or linux as operating system.Then what will be the shell script for the same and also if the PC has linux in it then we have to find if it is occupied or unoccupied. If the PC has windows in it then we have to find if it is... (6 Replies)
Discussion started by: akansha singh
6 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripting

Hey I have a data in the file named as outputFile.txt. The data is in the format 123456,12345678912345,400,09/09/09,INACTIVE. I want this output without commas ie 12345612345678912345400090909INACTIVE. Please tell me what to do and clear explain all the terms, as I am new to it. (6 Replies)
Discussion started by: sampandey31
6 Replies

5. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

7. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

8. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

9. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question