Multiple input and save in windows format


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-19-2015
Multiple input and save in windows format

The below code works great if the user inputs a single value. The sed command applies the NM_ with the user input it is saved to a file. However, if two values are entered the below does not work. Can both values be saved at the same time if they are entered in windows format? Thank you Smilie.

Code:
 gjb2() {
    printf "\n\n"
    printf "What is the id of the patient getting GJB2 analysis  : "; read id
    printf "Enter variant(s): "; read variant
	
	[ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
	
	# save file in windows python directory
    printf "%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
	
	# add transcript
	sed -i '$a NM_004004.5:' c:/Users/cmccabe/Desktop/Python27/$id.txt
    printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
	add2text ${id}.txt
	gjb2name
}

Maybe:
Code:
 awk 'NR!=FNR{print L[FNR],$0; next} $1=="variant"{I=$2}
    $1=="Name"{L[++p]=I FS $2}' $variant $variant > $id.txt

Code:
 user enters: c.74G>A

1 value output
NM_004004.5:c.74G>A

user enters:c.79G>A,c.283G>A

current 2 value output
NM_004004.5:c.74G>A,c.283G>A

Desired 2 value output
NM_004004.5:c.74G>A
NM_004004.5:c.283G>A


Last edited by cmccabe; 03-19-2015 at 02:59 PM..
# 2  
Old 03-19-2015
That depends on the shell you are using. In a recent bash try reading into an array:
Code:
IFS="," read -a TArr <<<"c.79G>A,c.283G>A"
echo ${#TArr[@]}
2
echo ${TArr[@]}
c.79G>A c.283G>A

and loop through the array.

BTW, help me out - what are your intentions here:
Code:
                   printf "%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
# add transcript     sed -i '$a NM_004004.5:' c:/Users/cmccabe/Desktop/Python27/$id.txt
       printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt

You create a file, the transcript is commented out, and then you overwrite the newly created file? Quite misleading for the reader ... I'd propose to get your act together and streamline the script.
# 3  
Old 03-19-2015
Code:
 printf "%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
# add transcript sed -i '$a NM_004004.5:'c:/Users/cmccabe/Desktop/Python27/$id.txt
printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt

The user inputs the variant and the sed command appends the transcript at the end (after the variant) So like this c.79G>ANM_004004.5:

the printf re-orders that to NM_004004.5:c.79G>A and saves that file in the python directory. Probably not the most efficient, but I will take your advice and work on it.

Out of curiosity do you find more scientists, especially genomic specialists, learning to program. Just curious because the data is huge and bioinformatics is becoming more important. Thank you Smilie.

---------- Post updated at 01:57 PM ---------- Previous update was at 01:42 PM ----------

Maybe:


Code:
 gjb2() {
    printf "\n\n"
    printf "What is the id of the patient getting GJB2 analysis  : "; read id
    printf "Enter variant(s): "; read variant
	
	[ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
	
    printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
while true
do
           IFS="," read -a TArr <<<"$variant"
           echo ${#TArr[@]}
           2
           echo ${TArr[@]}
           $variant
done
	add2text ${id}.txt
	gjb2name
}

Thank you Smilie.
# 4  
Old 03-19-2015
The printf "NM_004004.5:%s\n" ... does NOT re-order anything, it OVERWRITES the former file, destroying any work done on it before.

BTW - the sed line is commented out.

Yes, we do see quite some biological questions in these fora, dealing with large files...
# 5  
Old 03-19-2015
I removed the sed line as it is not necessary but the below code is not correct is it:

Code:
  gjb2() {
    printf "\n\n"
    printf "What is the id of the patient getting GJB2 analysis  : "; read id
    printf "Enter variant(s): "; read variant
 
 [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
 printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt

while true
do
           IFS="," read -a TArr <<<"$variant"
           echo ${#TArr[@]}
           2
           echo ${TArr[@]}
           $variant
done
 add2text ${id}.txt
 gjb2name
}

If the user inputs c.79G>A,c.283G>A

then in the file created:
NM_004004.5:c.79G>A
NM_004004.5:c.283G>A

Thank you Smilie.
# 6  
Old 03-19-2015
Quote:
Originally Posted by cmccabe
. . .
Code:
 gjb2() {
    printf "\n\n"
    printf "What is the id of the patient getting GJB2 analysis  : "; read id
    printf "Enter variant(s): "; read variant
    
    [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
    
    printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
while true
do
           IFS="," read -a TArr <<<"$variant"
           echo ${#TArr[@]}
           2
           echo ${TArr[@]}
           $variant
done
    add2text ${id}.txt
    gjb2name
}

No. Try sth. like (untested)
Code:
        printf "Enter variant(s): "; IFS="," read -a variant
        
        [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
        [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return

        for ((i=0; i<${#variant[@]}; i++))
                do printf "NM_004004.5:%s\n" ${variant[$i]} >> c:/Users/cmccabe/Desktop/Python27/$id.txt
        done

You may need to remove the target file before the loop.
This User Gave Thanks to RudiC For This Post:
cmccabe (03-19-2015)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to save a file directly into windows from UNIX? Little Shell Programming and Scripting 2 08-02-2015 01:24 PM
Input password to bash script, save, and enter when needed jbrass Shell Programming and Scripting 2 07-11-2015 01:42 AM
Save input as text in directory cmccabe Shell Programming and Scripting 8 03-10-2015 01:23 PM
Get the input from user and save it as .txt file Padmanabhan Shell Programming and Scripting 2 07-10-2013 08:19 AM
Format input file in unix i150371485 Shell Programming and Scripting 4 10-15-2012 10:25 AM
Open Text file input data and save it. asavaliya Shell Programming and Scripting 1 08-08-2012 05:24 PM
Script to port a file from unix and save in windows dll_fpga Shell Programming and Scripting 1 07-08-2012 01:52 AM
Converting windows format file to unix format using script sarbjit Shell Programming and Scripting 5 12-21-2010 01:00 AM
How to add data from 2 input files and save it in 1 output file redse171 Shell Programming and Scripting 4 12-16-2010 12:57 AM
<power save [ input 1 ]> philo_71 Hardware 0 03-26-2010 12:04 PM
Grep multiple lines and save to a file chssastry Shell Programming and Scripting 10 09-07-2009 12:00 PM
Save Excel file as .txt in UNIX format jroyalty UNIX for Dummies Questions & Answers 2 04-08-2009 03:46 PM
Need to validate a date input format rajugp1 Shell Programming and Scripting 2 02-02-2009 02:16 PM
Validating the input date format Sharmila_P Shell Programming and Scripting 6 08-01-2008 10:05 AM
Input parameter format mpang_ Shell Programming and Scripting 1 04-12-2006 05:34 AM