Sponsored Content
Top Forums Shell Programming and Scripting Display match or no match and write a text file to a directory Post 302963974 by cmccabe on Friday 8th of January 2016 11:44:17 AM
Old 01-08-2016
Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget) with the match in it. If there is no match then no file needs to be created just displayed. Thank you Smilie.

Code:
#!/bin/bash

# url download
printf "establishing connection and downloading file, please wait"
cd 'C:\Users\cmccabe\Desktop\wget'
curl -# -o getCSV.txt http://xxx.xx.xxx.xx/file/name.csv

# enter user-defined id
printf "please enter id(s), use a comma between multiple: "; IFS="," read -a id

     # check to make sure something entered
	[ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
	
# search download using entered id
echo "searching, please wait" 
result=`grep -n "${id}" getCSV.txt`
        for ((i=0; i<${#id[@]}; i++))
              do printf ${id[$i] & ${result[$i]}} >> "C:\Users\cmccabe\Desktop\wget\match.txt"
        done
   printf "match found in line $result"
else
   printf "No match found! " && sleep 2
   fi

# additional
printf "Are there additonal patients?  Y/N "; read match_choice

    case "$match_choice" in
        [yY]) id="${id}"; echo "what is the id of the NGS patient: "; read id
              [ -z "id" ] && printf "\n No ID supplied. Leaving match function." && 
			      sleep 2 && exit
		esac


Last edited by cmccabe; 01-08-2016 at 03:17 PM.. Reason: added details
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

match text from two files and write to a third file

Hi all I have two files X.txt and Y.txt. Both file contains same number of sentences. The content of X.txt is The filter described above may be combined. and the content of Y.txt is The filter describ+ed above may be combin+ed. Some of the words are separated with "+"... (2 Replies)
Discussion started by: my_Perl
2 Replies

2. Shell Programming and Scripting

Need Help - match file name and copy to Directory

I am trying to sort the following files from folder Bag to Apple, Cat Food, Dog Food. I can get all of the files I want into a new folder, but not sure of the best approch to get them to their final directory My Files ========== apple.1234.ext apple.1235.ext cat food 101.ext Cat Food... (2 Replies)
Discussion started by: mtschroeder
2 Replies

3. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

4. Shell Programming and Scripting

fuzzy sequence match in a text file

Hi Forum: I have struggle with it and decide to use my eye ball to accomplish this. Basically I am looking for sequence of date inside a file. If one of the sequence repeat 2-3 time or skip once; it's still consider a match. input text file: Sep 6 A Sep 6 A Sep 10 A Sep 7 B Sep 8... (7 Replies)
Discussion started by: chirish
7 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

6. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

7. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

8. Shell Programming and Scripting

Bash to add portion of text to files in directory using numerical match

In the below bash I am trying to rename eachof the 3 text files in /home/cmccabe/Desktop/percent by matching the numerical portion of each file to lines 3,4, or 5 in /home/cmccabe/Desktop/analysis.txt. There will always be a match between the files. When a match is found each text file in... (2 Replies)
Discussion started by: cmccabe
2 Replies

9. Shell Programming and Scripting

Insert text after match in XML file

Having a little trouble getting this to work just right. I have xml files that i want to split some data. I have 2 <name> tags within the file I would like to take only the first tag and split the data. tag example. From this. TAB<Name>smith, john</Name> to TAB<Name>smith,... (8 Replies)
Discussion started by: whegra
8 Replies

10. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
media_findname(3VOLMGT) 				Volume Management Library Functions				   media_findname(3VOLMGT)

NAME
media_findname - convert a supplied name into an absolute pathname that can be used to access removable media SYNOPSIS
cc [ flag ... ] file ... -lvolmgt [ library ... ] #include <volmgt.h> char *media_findname(char *start); DESCRIPTION
media_findname() converts the supplied start string into an absolute pathname that can then be used to access a particular piece of media. The start parameter can be one of the following types of specifications: /dev/... An absolute pathname in /dev, such as /dev/rdiskette0, in which case a copy of that string is returned (see NOTES on this page). /vol/... An absolute Volume Management pathname, such as /vol/dev/aliases/floppy0 or /vol/dsk/fred. If this supplied path- name is not a symbolic link, then a copy of that pathname is returned. If the supplied pathname is a symbolic link then it is dereferenced and a copy of that dereferenced pathname is returned. volume_name The Volume Management volume name for a particular volume, such as fred (see fdformat(1) for a description of how to label floppies). In this case a pathname in the Volume Management namespace is returned. volmgt_symname The Volume Management symbolic name for a device, such as floppy0 or cdrom2 (see volfs(7FS) for more information on Volume Management symbolic names), in which case a pathname in the Volume Management namespace is returned. media_type The Volume Management generic media type name. For example, floppy or cdrom. In this case media_findname() looks for the first piece of media that matches that media type, starting at 0 (zero) and continuing on until a match is found (or some fairly large maximum number is reached). In this case, if a match is found, a copy of the pathname to the volume found is returned. RETURN VALUES
Upon successful completion media_findname() returns a pointer to the pathname found. In the case of an error a null pointer is returned. ERRORS
For cases where the supplied start parameter is an absolute pathname, media_findname() can fail, returning a null string pointer, if an lstat(2) of that supplied pathname fails. Also, if the supplied absolute pathname is a symbolic link, media_findname() can fail if a read- link(2) of that symbolic link fails, or if a stat(2) of the pathname pointed to by that symbolic link fails, or if any of the following is true: ENXIO The specified absolute pathname was not a character special device, and it was not a directory with a character special device in it. EXAMPLES
Example 1: Sample programs of the media_findname() function. The following example attempts to find what the Volume Management pathname is to a piece of media called fred. Notice that a volmgt_check() is done first (see the NOTES section on this page). (void) volmgt_check(NULL); if ((nm = media_findname("fred")) != NULL) { (void) printf("media named "fred" is at "%s" ", nm); } else { (void) printf("media named "fred" not found "); } This example looks for whatever volume is in the first floppy drive, letting media_findname() call volmgt_check() if and only if no floppy is currently known to be the first floppy drive. if ((nm = media_findname("floppy0")) != NULL) { (void) printf("path to floppy0 is "%s" ", nm); } else { (void) printf("nothing in floppy0 "); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
cc(1B), fdformat(1), vold(1M), lstat(2), readlink(2), stat(2), free(3C), malloc(3C), volmgt_check(3VOLMGT), volmgt_inuse(3VOLMGT), volmgt_root(3VOLMGT), volmgt_running(3VOLMGT), volmgt_symname(3VOLMGT), attributes(5), volfs(7FS) NOTES
If media_findname() cannot find a match for the supplied name, it performs a volmgt_check(3VOLMGT) and tries again, so it can be more effi- cient to perform volmgt_check() before calling media_findname(). Upon success media_findname() returns a pointer to string which has been allocated; this should be freed when no longer in use (see free(3C)). SunOS 5.10 31 Dec 1996 media_findname(3VOLMGT)
All times are GMT -4. The time now is 07:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy