Combine shell files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine shell files
# 1  
Old 10-31-2014
Combine shell files

The script below is an attempt to combine 3 shells into 1.

The first part: match.sh
prompts the user for an id of a patient and runs a match script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.

The second part: convert2annovar.sh
prompts the user for an id of a patient and runs a conversion script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.

The third part: table_annovar
prompts the user for the type of analysis and runs a script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.

I attached the .sh file as well. Thank you Smilie.

Last edited by cmccabe; 10-31-2014 at 05:51 PM..
# 2  
Old 10-31-2014
Question, does this run for you as expected?

Code:
+ ~ $ sh annovar.sh 
What is the id of the patient to be matched  : 3
': not a valid identifier `id
What panel: 3
': not a valid identifier `panel
annovar.sh: line 4: syntax error near unexpected token `$'in\r''
'nnovar.sh: line 4: `		case "$id" in

2 ~ $ sh annovar.sh 
What is the id of the patient to be matched  : a
': not a valid identifier `id
What panel: b
': not a valid identifier `panel
annovar.sh: line 4: syntax error near unexpected token `$'in\r''
'nnovar.sh: line 4: `		case "$id" in

2 ~ $

Already gave instructions how to avoid these in: https://www.unix.com/302922954-post2.html
The code looks very identical to your previous code.

Please show some more effort (than just copy paste previous thread into a single file), you seem quite capable looking at your perl lines.

Thank you

---------- Post updated at 22:54 ---------- Previous update was at 22:33 ----------

However, to give you a hint on how to avoid the 'goto's, here is a little example:
Code:
#!/bin/bash
# Loop menu example
# 2014.10.31 by sea
################### 
#
#	Variables
#
	show_menu=true
	menu=( "Entry One" "Another two" "All good things are three" )
	func_show() { # "MESSAGE STRING"
	# Prints passed argument
	# Returns nothing
		printf '\n\t%s\n\n' "$1"
	}
#
#	Display & Action
#
	clear
	while $show_menu
	do	printf '#----------------------#\n%s\n' "Please select your task:"
		select entry in "${menu[@]}" Back
		do	case "$entry" in
			Back)		show_menu=false
					;;
			"Entry One")	func_show "first code (index id 0) :: $entry"
					;;
			"${menu[2]}")	func_show "third code :: ${menu[${#menu[@]}-1]}"
					;;
			*)		func_show "anything else (index id 1) :: $entry"
					;;
			esac
			break
		done
	done

Hope this helps

Last edited by sea; 10-31-2014 at 07:02 PM..
# 3  
Old 11-03-2014
The code is similar in that it is the same basic structure with additional functionality trying to be added. Being new to awk and learning I tried following your example (thank you for that):

Code:
 #!/bin/bash			
show_menu=true
	menu=( "[yY]" "[nN]" )
	func_show() { # "MESSAGE STRING"
	# Prints passed argument
	# Returns nothing
		printf '\n\t%s\n\n' "$1"
	}
#
#	Display & Action
#
	clear
	while $show_menu
	do	printf '#----------------------#\n%s\n' "Are there additonal patients to be matched"
		select entry in "${menu[@]}" Back
		do	case "$entry" in
			Back)		show_menu=false
					;;
			"[yY]")	func_show "perl -aF/\\t/ -lne 'BEGIN{%m=map{chomp;s/\cM|\cJ//g;$p=join("\t",(split/\t/)[4,5]);($p,$_)} <>;$m{"#CHROM\tINFO"}=$m{"Chr\tSegment Position"}};/SEGPOS=(\d+)/ || /\t(INFO)\t/ or next;$p=$F[0]."\t".$1;exists $m{$p} and print join("\t",$_,$m{$p})' ${id}_${panel}_${OMR}.txt < ${id}_${panel}_${OMR}_Filtered.vcf > ${id}_matched.vcf (index id 0) :: $entry"
					;;
			"${menu[2]}")	func_show "printf "Does the file need to be converted  : " ; read id :: ${menu[${#menu[@]}-1]}"
					;;
			*)		
			esac
			break
		done
	done

This is just the first section of the script. If a "Y" response is given it will run a perl command, but if "N' is given it prompts the user and thats all. Is that correct? Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

Korn shell Script to combine Two files in one

Hello All , I am new to this Forum, I am trying to write a script to combine two data files with 1 column in common and others columns are different . File1 Apple 29 tomatao 4 grapes 25 File2 Apple fruit tomatao veg grapes fruit other (3 Replies)
Discussion started by: gagan0119
3 Replies

3. Shell Programming and Scripting

Combine shell files

I am hoping the attached shell file is at least somewhat close to this. Combining two shell file into one, where depending on the user input of"y" or "n" different commands are run. Thank you :). So first he user is asked for an ID to match, once the id is entered a script is run that uses... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Combine files

I have n of files with ending with _ZERO.txt need to combine all file ending with _ZERO.txt into 1 file ex: A_ZERO.txt 1 2 B_ZERO.txt 3 4 Output: FINAL.txt 1 2 (3 Replies)
Discussion started by: satish1222
3 Replies

5. UNIX for Dummies Questions & Answers

Combine files

i have 3 files: file1, file2 and file3 file1 has this content: #!/bin/ksh sqlplus username/password@Servername << EOF file2 has this content: drop table dropme cascade constraints; file3 has this content: EOF all said and done, file1, file2 and file2 will look like... (1 Reply)
Discussion started by: lawsongeek
1 Replies

6. UNIX for Dummies Questions & Answers

Combine two files using shell script

I need to combine two files based on the content in first column and combine it into one file . For example : file1: A 10 B 20 C 30 D 40 File2: B 200 E 500 A 100 D 400 Need the output in this format: file 3 : column 1 Column 2 Column 3 A 10 100 B 20 ... (4 Replies)
Discussion started by: tsm2011
4 Replies

7. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

8. Shell Programming and Scripting

how to combine two files into one file using shell scrip

eg. file 1 has: 4 0 8628380 653253 0 0 0 0 0 0 2 0 8626407 655222 0 0 0 0 0 0 4 0 8633729 647892 0 0 0 0 0 0 5 0 8646253 635367 0 0 0 0 0 0 file 2 has: 4798 48717 11554 5408 56487 14359 6010 58415 15220 5541 41044... (2 Replies)
Discussion started by: netbanker
2 Replies

9. Shell Programming and Scripting

combine 3 excel files using shell.

Is there any way to combine 3 excel files into one comma separated file, after removing the header row from all the three files. Is this possible? I have looked in FAQ and I did not find anything. Appreciate any suggestions or links to resources. Radhika. (11 Replies)
Discussion started by: radhika
11 Replies

10. HP-UX

How to combine 2 different files

Hi : I have a file containing the print queues with their IP address. I wanted to combine the 'lpstat' output with their respective IP address. For example : zebhtrmb-6078 lgonzale priority 0 Mar 17 11:50 on zebhtrmb with zebhtrmb-6078 lgonzale priority 0 ... (1 Reply)
Discussion started by: rdasari
1 Replies
Login or Register to Ask a Question