Combine shell files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine shell files
# 1  
Old 11-07-2014
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 Smilie.

So first he user is asked for an ID to match, once the id is entered a script is run that uses that id. Following completion of the match the user is asked if there are additional files and depending on the response of "y' or "n" a script is run or another user prompt results.
# 2  
Old 11-07-2014
"[yY]") func_show --> [yY]) func_show
Note the missing quotes.

They are missing since we want to do REGEX, not STRING compare.

Otherwise it will only execute if user entered a literal: [yY]
The 2nd case statement ${menu[2]} was back in the original threads, just as an example how to use the numeric value of the array.
However, it w/could work, IF the array item was properly formated -- it lacks the same cause as: yY, but in this case, just let away the quotes.

Also, but just from the looks of it, untested, your perl command needs some care regarding escape chars for the quotes within the perl command.

HINT: Try simpler scripts, get used to the syntax before doing such things you do since a week Smilie

Hope this gets you started.

Last edited by sea; 11-07-2014 at 03:11 PM..
# 3  
Old 11-08-2014
Made a few changes, hopefully they are right, but I am getting this error:
Code:
 $ bash ~/newbatch.sh
What is the id of the patient to be matched  : H62947
What panel: Epilepsy70
/home/cmccabe/newbatch.sh: line 5: syntax error near unexpected token `'C:\Users\cmccabe\Desktop\annovar''
/home/cmccabe/newbatch.sh: line 5: `            cd 'C:\Users\cmccabe\Desktop\annovar''


Code:
 
#!/bin/bash
	    printf "What is the id of the patient to be matched  : "; read id
	    printf "What panel: "; read panel
		case "$id" in
		cd 'C:\Users\cmccabe\Desktop\annovar'
	    	    OMR=Output_Mutation_Report
			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
		;;
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
					;;
			[nN])	func_show "printf "Does the file need to be converted  : " ; read id :: ${menu[${#menu[@]}-1]}"
			while true
do
        printf "Enter ID  : " ; read id
		cd 'C:\Users\cmccabe\Desktop\annovar'
        [ -z "$id" ] && break
        [ "$id" = "end" ] && break
        perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
done
					;;
			*)		
			esac
			break
		done
	done

Thanks Smilie.
# 4  
Old 11-08-2014
show_func expects a single string, therefor you must pass 'anything' you pass, as a single string.

What is the (terminal) output of (by itself):
Code:
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

And for the case itself, you need to embrace that commabd by : "$( CMD )" (including the quotes!), where CMD is the complete perl command, when called by itself returns exactly what you want.

Its not Windows Smilie
It linux, so try either one of:
  • $HOME/Desktop/annovar
  • /home/annovar/Desktop/annovar
  • /home/$USER/Desktop/annovar
  • $XDG_DESKTOP_DIR/annovar

Hope this helps
# 5  
Old 11-08-2014
The terminal output of the perl command is attached: it basically matches two separate files and combines them into one and excludes non-unique values. I am not sure I follow what you are saying about the syntax of the perl function, but made some changes.
I am using cygwin on a windows 7 machine Thank you very much Smilie

The cd line as is works if the shells are run separate but not when they are combined.

Code:
#!/bin/bash
	    printf "What is the id of the patient to be matched  : "; read id
	    printf "What panel: "; read panel
		case "$id" in
		cd 'C:\Users\cmccabe\Desktop\annovar'
	    	    OMR=Output_Mutation_Report
			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
		;;
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])	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
					;;
			[nN])	func_show "printf "Does the file need to be converted  : " ; read id :: ${menu[${#menu[@]}-1]}"
			while true
do
        printf "Enter ID  : " ; read id
		cd 'C:\Users\cmccabe\Desktop\annovar'
        [ -z "$id" ] && break
        [ "$id" = "end" ] && break
        perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
done
					;;
			*)		
			esac
			break
		done
	done

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

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... (2 Replies)
Discussion started by: cmccabe
2 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