Multiple input and save in windows format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple input and save in windows format
# 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:
# 7  
Old 03-19-2015
That worked great. 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

Seen Windows pc, having all the features of Linux, could exe, read and edit save like windows

Hi, totally new to linux base using windows when started learning and using computers. but i remember that one pc was there , look alike windows desktop, but could not do the task as windows just click and open and view edit etc. But, you could do a little differently even saving in and opening... (8 Replies)
Discussion started by: jraju
8 Replies

2. Shell Programming and Scripting

How to save a file directly into windows from UNIX?

Hi, How can i save a file directly into my windows file system by running a shell script from my unix file system. I need to fetch data from a database and save it in a file. Since the data downloaded from database is huge, if i save it in the unix file system, the space in my home directory... (2 Replies)
Discussion started by: Little
2 Replies

3. Shell Programming and Scripting

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

4. Shell Programming and Scripting

Save input as text in directory

I am having a little trouble with some things using the code below: 1. printf "Enter variant: "; read variant The user enters the variant and that value is used in the python script. However, I am not sure how to save that value inputed as a text file in a specific directory... (8 Replies)
Discussion started by: cmccabe
8 Replies

5. Shell Programming and Scripting

Get the input from user and save it as .txt file

Hi friends, I am pretty new to shell scripting, please help me in this Scenario. for example, If I have one file called input.txt once I run the script, 1.It has to delete the old input.txt and create the new input.txt (if old input.txt is not there, no offence, just it has to create a... (2 Replies)
Discussion started by: Padmanabhan
2 Replies

6. Shell Programming and Scripting

Open Text file input data and save it.

Hi Guys, I have blank file A.txt I will run the script xyz.sh First i want to open a.txt file... Now i will enter some data like XYZ ABC PQR .. Save it and keep continue my script.... END of my script. Thanks (1 Reply)
Discussion started by: asavaliya
1 Replies

7. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

8. Shell Programming and Scripting

How to add data from 2 input files and save it in 1 output file

Hi, i have 2 input files which are file1.txt and file2.txt. I need to extract data from file1.txt and file2.txt and save it in file3.txt like example below:- File1.txt ID scrap1 Name scrap1 start 1 end 10 ID scrap2 Name scrap2 start 11 end ... (4 Replies)
Discussion started by: redse171
4 Replies

9. Hardware

<power save [ input 1 ]>

hello on my ultra 5 (under debian) obp since I activated an error saving mode display. Since it starts and displays <power save >, then this is prologue to sleep for hours. i can ejecting the cdrom works, I hear the fans .... I have not access of OpenBoot (stop + a). can i do an hard... (0 Replies)
Discussion started by: philo_71
0 Replies

10. UNIX for Dummies Questions & Answers

Save Excel file as .txt in UNIX format

I have some files created in Excel that have to be saved as .txt files in order to load them into our accounting system. I can save the files as .txt files through Excel, but I then have to open them in TextPad and do a save as to change the Format from PC to UNIX. Is there a way to skip this step... (2 Replies)
Discussion started by: jroyalty
2 Replies
Login or Register to Ask a Question