User prompt for perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting User prompt for perl
# 1  
Old 09-25-2014
User prompt for perl

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})' 12345_Marfan20_Output_Mutation_Report.txt < 12345_Marfan20_Output_Mutation_Report_Filtered.vcf > 12345_matched.vcf

The above perl script is used to merge two large data sets into 1 file. Is it possible to prompt the user to enter in the ID and panel? The same format is used each time and the only 3 things that change are the ID in italic and the panel in bold.

For example, the user would be prompted "Enter ID" = 12345, then asked "What panel" = Marfan20

the answers to the questions would be placed in the indicated places in the script. Thanks Smilie.
# 2  
Old 09-25-2014
Is it allowed to not be a one-liner? (Something 3 screens wide should not have been a 1-liner...)
# 3  
Old 09-25-2014
When I open the code using linux it is three lines, not sure why its one on here (maybe windows).

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})'
W34903_Noonan14_Output_Mutation_Report.txt < W34903_Noonan14_Output_Mutation_Report_Filtered.vcf > W34903_matched.vcf

Thanks.
# 4  
Old 09-25-2014
Of course it is possible to prompt the user for some input in perl, but it's somehow hard to use this input outside of the script, especially in the case of this one-liner, thus following bash script might be a viable workaround:
Code:
#!/bin/bash

echo -n "Enter ID  : "; read id
echo -n "What panel: "; read panel

OMR=Output_Mutation_Report

perl -aF/\\t/ -lne 'BEGIN ... ' $id_$panel_$OMR.txt < $id_$panel_$OMR_Filtered.vcf > $id_matched.vcf

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to prompt user to define a variable?

Hi everyone, Is it possible to define blank vaianbles and prompt user to fill them during the script execution? A very simple example: INPUT= OUTPUT= cut -f1-4 $INPUT | sed 's/hello/goodbye/g' | sort -uV > $OUTPUTThank you in advance! Best wishes (2 Replies)
Discussion started by: lsantome
2 Replies

2. Shell Programming and Scripting

Script to prompt user to enter data

Hi All I have a script that moves files from one dir to another dir based on date, but I would like to change it in a way that whoever is going to run to enter the dates in which files will be removed. This is my script: #!/bin/sh touch -mt 201302250000 /tmp/ref3 touch -mt 201302282359... (14 Replies)
Discussion started by: fretagi
14 Replies

3. UNIX for Dummies Questions & Answers

Linux user prompt

Hi, I cant seem to get this right. Lets say I have root privileges and I wanted: a ) edit the user prompt to show "linux1234$" whenever they log-in. also b ) Show a message for users upon logging in. I know a) has something to do with editing PS1. but how to only apply the change for users?... (1 Reply)
Discussion started by: Azi
1 Replies

4. Shell Programming and Scripting

How to use newgrp or sg in user mode without password prompt?

Hi, Is it possible to call newgrp or sg from user mode without password prompt in a Linux script? Thank you. hce (2 Replies)
Discussion started by: hce
2 Replies

5. Shell Programming and Scripting

Limit a user's login prompt upon logon

Hey Am new to scripting in aix 5.3 I need to write a script to limit a user's logon prompt to an interactive menu based upon logon and nothing else. Any ideas much appreciated. :wall: (4 Replies)
Discussion started by: mills
4 Replies

6. Shell Programming and Scripting

Prompt user for info

Please forgive this newbie question. I have a need to create a script that asks a user for information. Something like: What is the name: $NAME_TYPED_HERE Is $NAME_TYPED_HERE Correct ? YES (NO would go back to -What is the Name-) mkdir then goes on behind the scene and makes folder called... (1 Reply)
Discussion started by: crowman
1 Replies

7. AIX

Not able to create a new user through prompt and smit

Hi, I tried to create a user through smit and command and getting the error: 3004-698 Error committing changes Please suggest. Regards, Ravi Dwivedi (1 Reply)
Discussion started by: dwiravi
1 Replies

8. UNIX for Dummies Questions & Answers

change user> to user@host> ssh prompt

Hi, I was wondering how to change the prompt for my ssh login. At the moment it is like user> while I'd like it to be as user@host> It is in the .bash_profile or .ssh ??? Thanks (2 Replies)
Discussion started by: pmasterkim
2 Replies

9. Shell Programming and Scripting

Help with a user prompt

Hi, I am attempting to write a BASH shell script that will prompt users for responses before accomplishing some tasks. Due to the top-to-bottom nature of shell scripts, asking users questions in sequence is quite easy. However, I am interested in allowing users to go back to and re-answer... (1 Reply)
Discussion started by: msb65
1 Replies

10. Shell Programming and Scripting

Prompt User for Pgm Output Destination

SCO Open Server 5 A program that I am working with outputs data to a system or printer with the traditional output > lp This output line along with some other job output formatting information is stored as a defined output within the program so that the average user scrolls the list of... (0 Replies)
Discussion started by: termite
0 Replies
Login or Register to Ask a Question