Search and Parse string from inside a File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Search and Parse string from inside a File
# 1  
Old 11-08-2007
Search and Parse string from inside a File

Hello,
I barely know the basics, but I am very determined to learn. I want to parse a few characters from each row, use that string to search another file and display the line number where I found the value in the file. I don't know if this can all be done on the command line, so I am creating a shell script that does this so far:

DIR = /cygdrive/c/temp/9*.txt
for item in parseFile.txt
do
foundValue = $item //do not know what command to use to search for a
//value and to parse from the file.
egrep -l "$item" $DIR //how do I display the line number where I found
//the item
done

Thanks for your help! Smilie
# 2  
Old 11-08-2007
grep -n show the line number.

Your explanation is not clear enough to me for me to provide any more help.
What do you mean by parse - find the first 3 characters, find the 16th field, what?

Your for loop needs help
Code:
while read item
do
 # stuff goes here
done < parsefile.txt

On variable assignments - NO spaces allowed
Code:
foundValue = $item  # bad
foundValue="$item"  # good  I put quotes around item in case there were spaces in $item
# quotes may not be needed - I dunno.

# 3  
Old 11-08-2007
Hi Jim,
Thanks for your feedback and valuable information.

Perhaps I should also add that I'm using the Borne Shell and now realize that I cannot use the
"For Do Done" loop.

I want to search a file for a value, then search if this value is contained in another file. For example: Parse 21909 from FileA.txt (e.g. 1234|3234|21909), then search within several other files for 21909 . If value exist, display file name and line number where this value exists. Then repeat parsing in FileA.txt for the next value 97909 (e.g. 5284|1134|97909), search 97909 within several other files and see if this values exist. If so, display file name and line number where this value exists.

Thanks again!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies

2. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

3. Shell Programming and Scripting

Urgent - Search a string inside awk

I need to search for string which is formed from the awk input file in a file given as input through -v option. I tried using the while (getline filename) and match(). But this approach is consuming lot of time as the input file has thousands of records. Please suggest any alternative. Thanks! (0 Replies)
Discussion started by: Cool
0 Replies

4. Shell Programming and Scripting

Search inside a file, PERL

HEllo!! I need a script in perl that see inside a file(file.txt) that has only one row. The row contains only this text: logs_yearly = 20120628113345 I want that the script does this: "Search in the file, if the date 20120628 is actual date" Thank you!! ---------- Post... (4 Replies)
Discussion started by: super_sun
4 Replies

5. Shell Programming and Scripting

Search string and parse

Input file 0792 to 2450 iadmssql7: Copy: CNJ R1: Replication volumes: Replication set: RSet 1 Replication size: 200.00GB SAN Info: 200.00GB DGC VRAID CX4-960 LUN 17 (17) RPA Port WWN Ctrl ... (0 Replies)
Discussion started by: greycells
0 Replies

6. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

7. Shell Programming and Scripting

Search inside a Jar file..

Hey Guys, I need to search inside all the jar files of my directory for a specific string. Can anyone guide me as to how i can do it. I need this urgently please. More specifically i need to search for a class file name in the jar files. Thanks in advance :-) (4 Replies)
Discussion started by: srikumar_cs
4 Replies

8. Shell Programming and Scripting

Parse String in XML file

Hello All, I am new to this and I need to parse an XML file. Here's the XML Input File: <Report version="1.2"> <summary fatals="0" testcases="1" expected_fails="0" unexpected_passes="0" warnings="9" tests="21" errors="0" fails="1" passes="20" /> <testresult... (4 Replies)
Discussion started by: racbern
4 Replies

9. Shell Programming and Scripting

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it? using grep command.. Bit urgent.. pls..help me (2 Replies)
Discussion started by: senraj01
2 Replies

10. Shell Programming and Scripting

Perl: Search for string then parse next line

Hi All, I have a file that I need to be able to find a pattern match on one line then parse data on the next or subsequent lines - I will know which line needs to be parsed beforehand. This is what I currently have: while (<COMMAND_OUT>) { if ($_ =~ m/TEST/) { ... (4 Replies)
Discussion started by: pondlife
4 Replies
Login or Register to Ask a Question