Sponsored Content
Top Forums Shell Programming and Scripting Search a text and return the text from file Post 302950505 by my_Perl on Saturday 25th of July 2015 06:25:51 PM
Old 07-25-2015
Search a text and return the text from file

Hi

I have a set of input strings in a pattern as given below

string1 string2 string3 string4 string5


I need to search this sequence of strings from a file in such a way that the first two strings (string1 and string2) and last two strings (string4 and string5) should match with the strings in the SECOND column of a text file (consisting of three columns) after the comparison of the numbers from the respective column.

So, the script will perform searching for the strings which matches string1, string2, string4 and string5 from a big text file called TEXTFILE.TXT . Then, it'll return the string which has the biggest number (-ve number) in FIRST column and the string which has the biggest -ve number in the third column.


A sample file format of the TEXTFILE.txt is given below. The FIRST and SECOND columns are separated by a tab and SECOND and THIRD columns are separated by a tab and a space. The strings in the SECOND columns are separated by a space. There are multiple entries in the SECOND column which may be of single string upto five strings.

For example, my input is

Code:
string1  string2  string3 string4  string5

hai        wafam   cherol   makha   palli

Now there are four entries which matches the input in the textfile.So, the output will be the two string sets :


Code:
hai wafam cherolna makha palli
hai wafam cherolduna makha palli

File format of TEXTFILE.TXT

Code:
-1.391722       hai wafam cherolna makha palli     -0.6328273
-2.922845       hai wafam cherolduna makha palli -0.1190167
-2.915667       hai wafam cherolsina makha palli  -0.5702463
-2.927181       hai wafam paochena makha palli  -0.1963889
-2.925497       hai wafam khangnaduna   -0.6328273
-2.855543       hai wafam ngasigi 
-2.926619       hai wafam thamkharabani
-1.635051       hai wafam thamlamle    -0.4567362
-1.078001       hai wafam thamlamli    -0.8960688
-1.023442       adubu madu makhada yaakhidre haikhre -0.1234433
-1.432234       adubu madu ma yaakhidre haikhre  -0.5432345

I need help to write a script to perform above task. Thanks in advance .
Moderator's Comments:
Mod Comment Please use CODE tags (not HTML) tags for all sample input, output, and sample code segments.

Last edited by my_Perl; 09-15-2015 at 09:17 PM.. Reason: Change HTML tags to CODE tags and add CODE tags.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

2. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

3. Shell Programming and Scripting

search text file in file if this file contains necessary text (awk,grep)

Hello friends! Help me pls to write correct awk and grep statements for my task: I have got files with name filename.txt It has such structure: Start of file FROM: address@domen.com (12...890) abc DATE: 11/23/2009 on Std SUBJECT: any subject End of file So, I must check, if this file... (4 Replies)
Discussion started by: candyme
4 Replies

4. Shell Programming and Scripting

Search value in text file

Hi, I have the follwoing text file : db1;unrecoverable;0;20110728162548 db1;unrefreshed;1,NO_MV_VIEWS;20110728162548 xe1;Database;1;20110728162548 xe1;autoextensible;0;20110511112053 xe1;chk_offline_dbf;0;20110511112053 xe1;expiry_date;0;20110511112053 xe1;job;4;20110420111823... (2 Replies)
Discussion started by: yoavbe
2 Replies

5. Shell Programming and Scripting

bash: need to have egrep to return a text string if the search pattern has NOT been found

Hello all, after spending hours of searching the web I decided to create an account here. This is my first post and I hope one of the experts can help. I need to resolve a grep / sed / xargs / awk problem. My input file is just like this: ----------------------------------... (6 Replies)
Discussion started by: bash4ever
6 Replies

6. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

7. Shell Programming and Scripting

Match text from file 1 to file 2 and return specific text

I hope this makes sense and is possible. I am trying to match $1 of panel_genes.txt with $3 of RefSeqGene.txt and when a match is found the value in $6 of RefSeqGene.txt Example: ACTA2 is $1 of panel_genes.txt ACTA2 NM_001613.2 ACTA2 NM_001141945.1 awk 'FNR==NR {... (4 Replies)
Discussion started by: cmccabe
4 Replies

8. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

9. 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
All times are GMT -4. The time now is 05:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy