Linux shell script, search by an input string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux shell script, search by an input string
# 1  
Old 04-28-2018
Linux shell script, search by an input string

So, there is a large file where I have to conduct several search using bash shell scripting.
The file is like this:
Code:
TITLE and AUTHOR                                                     ETEXT NO.  Aspects of plant life; with special reference to the British flora,      56900  by Robert Lloyd Praeger  The Vicar of Morwenstow, by Sabine Baring-Gould                          56899  [Subtitle: Being a Life of Robert Stephen Hawker, M.A.]  Raamatun tutkisteluja IV, mennessä Charles T. Russell                    56898  [Subtitle: Harmagedonin taistelu]  [Language: Finnish]  Raamatun tutkisteluja III, mennessä Charles T. Russell                   56897  [Subtitle: Tulkoon valtakuntasi]  [Language: Finnish]  Tom Thatcher's Fortune, by Horatio Alger, Jr.                            56896  A Yankee Flier in the Far East, by Al Avery                              56895  and George Rutherford Montgomery  [Illustrator: Paul Laune]  Nancy Brandon's Mystery, by Lillian Garis                                56894  Nervous Ills, by Boris Sidis                                             56893  [Subtitle: Their Cause and Cure]  Pensées sans langage, par Francis Picabia                                56892  [Language: French]  Helon's Pilgrimage to Jerusalem, Volume 2 of 2, by Frederick Strauss     56891  [Subtitle: A picture of Judaism, in the century   which preceded the advent of our Savior]  Fra Tommaso Campanella, Vol. 1, di Luigi Amabile                         56890  [Subtitle: la sua congiura, i suoi processi e la sua pazzia]  [Language: Italian]  The Blue Star, by Fletcher Pratt                                         56889  Importanza e risultati degli incrociamenti in avicoltura,                56888  di Teodoro Pascal  [Language: Italian]  The Junior Classics, Volume 3: Tales from Greece and Rome, by Various    56887   ~ ~ ~ ~ Posting Dates for the below eBooks:  1 Mar 2018 to 31 Mar 2018 ~ ~ ~ ~  TITLE and AUTHOR                                                     ETEXT NO.  The American Missionary, Volume 41, No. 1, January, 1887, by Various     56886  Morganin miljoonat, mennessä Sven Elvestad                               56885  [Author a.k.a. Stein Riverton]  [Subtitle: Salapoliisiromaani]  [Language: Finnish]  "Trip to the Sunny South" in March, 1885, by L. S. D                     56884  Balaam and His Master, by Joel Chandler Harris                           56883  [Subtitle: and Other Sketches and Stories]  Susien saaliina, mennessä Jack London                                    56882  [Language: Finnish]  Forged Egyptian Antiquities, by T. G. Wakeling                           56881  The Secret Doctrine, Vol. 3 of 4, by Helena Petrovna Blavatsky           56880  [Subtitle: Third Edition]  No Posting                                                               56879  First love and other stories, by Iván Turgénieff                         56878


Now I have to search it with etext no, author name and title..
Like If I search by an etext no: like etext 56900: It should return



Code:
Aspects of plant life; with special reference to the British flora,      56900


Well I am new to shell scripting. And I can only read the file. With this:
Code:
#!/bin/sh read -p 'string to search ' searchstring grep --color searchstring GUTINDEX.ALL | #condition


I don't know what kind of condition I should use to search by author name or etext no....
# 2  
Old 04-28-2018
Welcome to the forum.

Unfortunately, with your above specification, I'm not sure what to do. Is that really a single line data file? What be the record separator? If you "search it with etext no, author name and title", why is the author missing in the sample result? And, what is that sample code supposed to do (after the syntax errors have been corrected)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command in Linux in a script where the search string has a space

I have a file xyz with the following content PPPL 0123 PPPL 0006 POFT 0923 POFT 1111 WENT 2323 SEND 2345 I also have another file named MasterFile where it contains the above mentioned data million times with different digits at the end for example some times it contains SEND 9999 or WENT... (4 Replies)
Discussion started by: knijjar
4 Replies

2. Shell Programming and Scripting

How to Search a string in a file in shell script?

I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
Discussion started by: Lalat
2 Replies

3. Shell Programming and Scripting

Shell script to search all files for every string in another file

Hello All I have a pattern.txt file in source directory ((/project/source/) in linux server and data looks like: 123abc17 234cdf19 235ifg20 I have multiple log files in log directory (/project/log/) in linux server and data for one log file looks like: <?xml version="1.0" processid... (11 Replies)
Discussion started by: pred55
11 Replies

4. Shell Programming and Scripting

UNIX shell script to search a string in a file

Hi folks, I am new for shell script, I hope somebody to help me to write shell script My requirement is below steps 1. I have apache access.log i.e located in /var/log/httpd/ Ex. 127.0.0.1 - - "GET... (14 Replies)
Discussion started by: Chenchireddy
14 Replies

5. Shell Programming and Scripting

Passing string as a input parameter for a shell script

Hi i have a shell script which needs a string as an input parameter. How to pass the string param as an input? In command line am running the script. for e.g., a="who is a buddy?" sh sample.sh $a Inside the script i get this input param as $1 but only the value "who" is accepted... (12 Replies)
Discussion started by: vidhyaS
12 Replies

6. Shell Programming and Scripting

Shell Script to Search for a particular String and copy the timestamp to a variable

Hi, We Perfrom Loads to the database through a Perl script which generates a statistics file. I need to read the statistics. the Statistics file looks something like below: Process Beginning - 08-26-2010-23.41.47 DB2 CONNECTION SUCCESSFUL! Ready to process and load file: FILENAME # of... (2 Replies)
Discussion started by: Praveenkulkarni
2 Replies

7. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

8. Shell Programming and Scripting

shell script to search a string and delete the content

Hi, I've a shell script e.g. #!/bin/bash echo "Enter the next hop id" read nhid echo "enter the IP address" read IP echo "enter the interface name" read name echo "enter the enable/disable state" read state exit 0 now from this script i want to search strings in another (.cam) ... (6 Replies)
Discussion started by: vic_mnnit
6 Replies

9. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies

10. UNIX for Dummies Questions & Answers

Search a string from list of input files

Hello, I am trying to match a string between line one and line two with in the file. But I dont want to search based on the given filename. Instead I want to search for all available files in the specific directory. Please help me on the above. (2 Replies)
Discussion started by: sivakumarvenkat
2 Replies
Login or Register to Ask a Question