Bash to select text and apply it to a selected file in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash to select text and apply it to a selected file in bash
# 1  
Old 09-29-2016
Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you Smilie

Code:
FILESDIR=/home/cmccabe/Desktop/ref/validation/val
PANELDIR=/home/cmccabe/Desktop/ref/validation/panels

PS3="please select a panel: "

cd "$PANELDIR"
select bed in $(ls *.txt)
do    [ "$panel" != "" ] && break
done

PS3="please select a file to analyze with a panel: "

cd "$FILESDIR"
select file1 in $(ls *.vcf)
do    [ "$file1" != "" ] && break
done
      printf "FILE is: ${file1} and will be used filtered to ${panel} \n"
      read -r -p "Is this correct? [y/N] " response
if [[ $response =~ ^[nN][oO]?$ ]]
then
echo 'please try again'  && exit
else

logfile="/home/cmccabe/Desktop/ref/validation/val/process.log"
for f in /home/cmccabe/Desktop/ref/validation/val/$file1 ; do
     echo "Start filter creation: $(date) - File: $f"
     bname=$(basename $f)
     pref=${bname%%_*.vcf}
     grep -wFf /home/cmccabe/Desktop/ref/validation/panels/$panel $f >/home/cmccabe/Desktop/ref/validation/filtered/${pref}_filtered.txt
     echo "End filder creation: $(date) - File: $f"
done >> "$logfile"
line 32: syntax error: unexpected end of file


Last edited by cmccabe; 09-29-2016 at 05:48 PM.. Reason: fixed typo
# 2  
Old 09-29-2016
If you would indent your code inside for, while, if, and similar constructs, it would be easier to see that you have an if, then, and else with no fi.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 09-29-2016
Did I add it in the wrong place? Thanks.

Code:
FILESDIR=/home/cmccabe/Desktop/ref/validation/val
PANELDIR=/home/cmccabe/Desktop/ref/validation/panels

PS3="please select a panel: "

cd "$PANELDIR"
select bed in $(ls *.txt)
do    [ "$bed" != "" ] && break
done

PS3="please select a file to analyze with a panel: "

cd "$FILESDIR"
select file1 in $(ls *.vcf)
do    [ "$file1" != "" ] && break
done
      printf "FILE is: ${file1} and will be used filtered to ${bed} \n"
      read -r -p "Is this correct? [y/N] " response
    if [[ $response =~ ^[nN][oO]?$ ]]
         then
         echo 'please try again'  && exit
    else
    fi
logfile="/home/cmccabe/Desktop/ref/validation/val/process.log"
for f in /home/cmccabe/Desktop/ref/validation/val/$file1 ; do
     echo "Start filter creation: $(date) - File: $f"
     bname=$(basename $f)
     pref=${bname%%_*.txt}
     grep -wFf /home/cmccabe/Desktop/ref/validation/panels/$bed $f >/home/cmccabe/Desktop/ref/validation/filtered/${pref}_filtered.txt
     echo "End filder creation: $(date) - File: $f"
done >> "$logfile"
syntax error near unexpected token `fi

# 4  
Old 09-29-2016
I have no idea what you are trying to do with this script. So, I don't know if the fi should follow the following assignment statement or follow the following for loop, or whether you just need to remove the empty else before the fi and leave the fi where it is???
# 5  
Old 09-29-2016
then or else in an if construct cannot have empty 'body'.
If you still want to have either a then or an else as stubs with nothing in them, follow this paradigm:
Code:
else
:
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I apply 'date' command to specific columns, in a BASH script?

Hi everyone, I have a situation in which I have multiple (3 at last count) date columns in a CSV file (, delim), which need to be changed from: January 1 2017 (note, no comma after day) to: YYYY-MM-DD So far, I am able to convert a date using: date --date="January 12, 1990" +%Y-%m-%d ... (7 Replies)
Discussion started by: richardsantink
7 Replies

2. Shell Programming and Scripting

Use same file selected in first bash process that has matching digits in it fot the second

In the below portion of a bash script the user selects a file from a directory. select file in $(cd /home/cmccabe/Desktop/NGS/API/5-14-2016/bedtools;ls);do break;done files in directory 123_base_counts.txt 456_base_counts.txt 789_base_counts.txt second portion of bash currently (user... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

Bash to select and save file in new directory

I am trying to select a file in bash and save it to a directory. The below does run but no selected file is saved. Thank you :). bash # select file printf "please select a file to analyze with entered gene or genes \n" select file in $(cd... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Bash to select panel then specific file in directory

I am using bash to prompt a user for a choice using: where a "y" response opens a menu with available panels that can be used. while true; do read -p "Do you want to get coverage of a specific panel?" yn case $yn in * ) menu; break;; * ) exit;; * ) echo... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

How to pass enter key or selected character in bash script?

hi, i've bash script thats working... but now i need to add a line....that prompts for user input....like yes and 1 as complete install.... so here's how it looks... $ cd 9200 (cd into directory) $./install (hv to type ./install to run install then ask for) ----do you want to... (4 Replies)
Discussion started by: kernel11
4 Replies

6. Shell Programming and Scripting

Reading a text file using bash

I've a file in linux with following text: ;ip address hostname put-location alt-put-location tftpserver 192.168.1.1 r01-lab1-net /mnt/nas1/fgbu/ /opt/fgbu/devicebackup 192.168.1.254Now I want to read these values and assign them to particular variables... (6 Replies)
Discussion started by: kashif.live
6 Replies

7. Shell Programming and Scripting

Select columns from a matrix given within a range in BASH

I have a huge matrix file which looks like this (example matrix): 1 2 3 5 4 5 6 7 7 6 8 9 1 2 4 2 7 6 5 1 3 2 1 9 As one can see, this matrix has 4 columns and 6 rows. But my original matrix has some 3 million rows and 6000 columns. For example, on this matrix I can define my task as... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. Shell Programming and Scripting

Drop down menu in bash for timezone select

Is there any way to implement a drop down menu selection in bash? This is on CDLinux which is a very minimal live CD and I am using it to install an image onto a hard drive. Part of that process is the timezone selection. There are just too many timezones to attempt to use the "select" command.... (1 Reply)
Discussion started by: simonb
1 Replies

10. UNIX for Dummies Questions & Answers

select in ksh, any guidance for bash?

I have a file driven menu using the select feature in ksh. I like doing it this way, however I would prefer running a bash. Is there some eqivalent way of doing this in a bash shell? ie select file in *.ascii  do typeset -u REPLY if  ; then... (1 Reply)
Discussion started by: Shakey21
1 Replies
Login or Register to Ask a Question