Sponsored Content
Top Forums Shell Programming and Scripting Bash to search file based off user input then create new file Post 302942784 by cmccabe on Friday 1st of May 2015 10:30:07 AM
Old 05-01-2015
When the bash menu is opened the getCSV file is downloaded and then the menu closes. Below is the code as is and what I am trying to do is when the menu is opened the file is downloaded, the user is prompted for the id, and once that is entered it is searched for in the file. While it is being searched for on the screen "searching, please wait" is displayed and when a match is found on the screen "match found in lijne..." is displayed and a file match.txt is written. Thank you for your help Smilie.

Code:
#!/bin/bash
cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv

search() {
    printf "\n\n"
    printf "What is the id of the NGS patient: "; read id
         [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
         [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
   
    printf "searching, please wait" 
result=`grep -n "${id}" getCSV.txt`
if [ -n "$result" ]; then
   echo "match found in line $result" >> match.txt
else
  echo "no match found"
fi
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search file, change existing value based on input (awk help)

I have a file (status.file) of the form: valueA 3450 valueB -20 valueC -340 valueD 48 I am tailing a data.file, and need to search and modify a value in status.file...the tail is: tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }' which will produce lines that look like this: ... (3 Replies)
Discussion started by: nortonloaf
3 Replies

2. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

3. Shell Programming and Scripting

Grepping a file based on input from a second file

how to grep a file based on another input file File1 ashu 1 ninetwo hari qwer 6 givefour jan fghj 8 noeight mar vbmi 7 noput feb -- --- File2 noput noeight --- -- Taking the input of grep as File2, a search need to be made in File1 giving File3 as output: (7 Replies)
Discussion started by: er_ashu
7 Replies

4. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

5. Shell Programming and Scripting

Search on date range of file based on user input

Hello I would like to ask for help with a script to search a directory that contains many log files and based on a users input after being prompted, they enter a date range down to the hour which searches the files that contain that range. I dont know how to go about this. I am hoping that the... (5 Replies)
Discussion started by: lostincashe
5 Replies

6. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

7. Shell Programming and Scripting

Search pattern in a file taking input from another file

Hi, Below is my requirement File1: svasjsdhvassdvasdhhgvasddhvasdhasdjhvasdjsahvasdjvdasjdvvsadjhv vdjvsdjasvdasdjbasdjbasdjhasbdasjhdbjheasbdasjdsajhbjasbjasbhddjb svfsdhgvfdshgvfsdhfvsdadhfvsajhvasjdhvsajhdvsadjvhasjhdvjhsadjahs File2: sdh hgv I need a command such that... (8 Replies)
Discussion started by: imrandec85
8 Replies

8. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

9. Shell Programming and Scripting

awk command to search based on 5 user input fields

Field1=”” Field2=”” Field3=”” Field4=”” Field5=”” USER INPUT UP TO 5 FIELDS awk -F , '{ if ( $3 == Field1 && $6 == Field2 && $8 == Field3 && $9 == Field4 && $10 == Field5) print $0 }' /tmp/rodney.outD INPUT FILE (Rodney.outD): ... (3 Replies)
Discussion started by: rmerrird
3 Replies

10. Shell Programming and Scripting

Automaticaly create function based off user input

I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss. If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files... (0 Replies)
Discussion started by: cmccabe
0 Replies
menu_pattern(3X)														  menu_pattern(3X)

NAME
menu_pattern - get and set a menu's pattern buffer SYNOPSIS
#include <menu.h> int set_menu_pattern(MENU *menu, const char *pattern); char *menu_pattern(const MENU *menu); DESCRIPTION
Every menu has an associated pattern match buffer. As input events that are printable characters come in, they are appended to this match buffer and tested for a match, as described in menu_driver(3X). The function set_menu_pattern sets the pattern buffer for the given menu and tries to find the first matching item. If it succeeds, that item becomes current; if not, the current item does not change. The function menu_pattern returns the pattern buffer of the given menu. RETURN VALUE
The function menu_pattern returns a pointer, which is NULL if the menu parameter is NULL. Otherwise, it is a pointer to a string which is empty if no pattern has been set. It does not set errno. The function set_menu_pattern may return the following error codes: E_OK The routine succeeded. E_BAD_ARGUMENT Routine detected an incorrect or out-of-range argument. E_BAD_STATE Routine was called from an initialization or termination function. E_NOT_CONNECTED No items are connected to menu. E_NO_MATCH Character failed to match. E_SYSTEM_ERROR System error occurred (see errno). SEE ALSO
curses(3X), menu(3X). NOTES
The header file <menu.h> automatically includes the header file <curses.h>. PORTABILITY
These routines emulate the System V menu library. They were not supported on Version 7 or BSD versions. AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond. menu_pattern(3X)
All times are GMT -4. The time now is 05:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy