Find string in file and find the all records by string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find string in file and find the all records by string
# 8  
Old 06-23-2015
what is the relationship between ABCD and BABA in the file, could you provide a data sample (not 1G, just an example of the desired string and the second desired string and how it is discovered?).
# 9  
Old 06-23-2015
Quote:
Originally Posted by mape
I need to find string like ABCD
PHP Code:
grep ABCD $FILE 
This grep gives me some records where is another string for instance BABA
and I need to find all records by BABA on $FILE

---------- Post updated at 02:21 AM ---------- Previous update was at 02:17 AM ----------

Just first its easy to find ABCD using by GREP ABCD $FILE

But the next step I dont know exactly how to write this.
I repeat: Is this a homework assignment? Homework assignments need to be posted in the Homework & Coursework Forum and require that a questionnaire be filled out as specified in the rules for that forum.

When you grep for a string in a file, we generally expect to find that string (not a different string); but, obviously, grep will give you an entire line, not just the string you matched. If you show us the format of the file you are processing and show us a real-life example with a sample input file (shown in CODE tags), a string that you want to search for in that sample input file, explain what variables should be set as a result of searching that sample file, and show us what secondary search you want to perform based on those results; we might be able to understand what you're trying to do and suggest a way to approach the problem.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 06-24-2015
As I see you dont know what I mean.

Log file consist of bunch of information about transactions.
Each transaction has session_id and by this session_id I can identify some important things.

But first of all I need to look up for instance information about login, so I use :
Code:
grep loginWithIdCode file_log.txt

I get record something like this:
Code:
0F3CE08D6E53C97CD9B54A862B493D57 DEBUG (JSONConverter): JSON Request: {"idCode":*****,"reqType":"loginWithIdCode"}

And string 0F3CE08D6E53C97CD9B54A862B493D57 means session_id and by this session_id I would like to get all records from log file.

It is much more clear ?

Last edited by Don Cragun; 06-24-2015 at 04:22 PM.. Reason: Change PHP tags to CODE tags, add CODE and ICODE tags.
# 11  
Old 06-24-2015
A clear, precise, and detailed specification "ab initio" including some meaningful and representative samples could have avoided a long discussion, as we can see again.

If the line with your search pattern is the first line to be found in the file, try
Code:
awk '/loginWithIdCode/ {PAT=$1} $0 ~ PAT' file

# 12  
Old 06-24-2015
When I look up session_id I would like to get all records again from log file which consist session_id.
# 13  
Old 06-24-2015
Is there something you need done that the code suggested by RudiC didn't do?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find previous string based on an input string?

Hi, I did some research but cannot find the right solution so hopefully someone can help me here. I have a long string format like: VAR=111:aaaa,222:bbb,333:ccc it could be VAR=111:aaa,222:bbb,333:ccc,444:ddd, etc what I looking for is eg. if I give ccc, it will return me 333... (2 Replies)
Discussion started by: netbanker
2 Replies

2. Shell Programming and Scripting

Find a string and print all lines upto another string

Ok I would like to do the following file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry. I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
Discussion started by: revaroo
3 Replies

3. Shell Programming and Scripting

Find string in file and append new string after

Hi All, I'm trying to insert a string into a file at a specific location. I'd like to add a string after the parent::__construct(); in my file. <?php if (! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends CI_Controller { function... (6 Replies)
Discussion started by: jjkilpatrick
6 Replies

4. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

5. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

6. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

7. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

8. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

9. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

10. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies
Login or Register to Ask a Question