Using Grep & find & while read line in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Grep & find & while read line in a script
# 1  
Old 04-13-2012
Using Grep & find & while read line in a script

Hello people!

I would like to create one script following this stage

I have one directory with 100 files

Code:
File001
File002
...
File100

(This is the format of content of the 100 files)

Code:
2012/03/10    12:56:50:221875936     1292800448912   12345 0x00    0x04    0

then I have one text file(IMSI.txt) with 5 numbers

Code:
12345 (Number A)
12346
12347
12348
12349

I Created this script:

Code:
for LINE in `cat /Aldo/IMSI.txt`
   do
      grep $LINE  /Aldo/File*
done | cut -d":" -f2-5 > /home/eir/Desktop/Aldo/encontrados.txt

to find the "numbers A" on the 100 files then print the line like

Code:
2012/03/10    12:56:50:221875936     1292800448912   12345 0x00    0x04    0

example: Find 12345 in the 100 files

Code:
2012/03/10    12:56:50:221875936     1292800448912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292859448912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292898758912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292823458912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292898348912   12345 0x00    0x04    0

to now.. all is working good!
but io have another problem... from the 100 files.. i would like to limit the files by date .. as before the March 22... i tried to use find

Code:
grep $LINE | find /opt/eir/var/tdr -mtime +22

but allways show me the directory of the file.. and i need the

Code:
2012/03/10    12:56:50:221875936     1292859448912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292898758912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292823458912   12345 0x00    0x04    0
2012/03/10    12:56:50:221875936     1292898348912   12345 0x00    0x04    0

Help me!

---------- Post updated at 11:25 AM ---------- Previous update was at 11:21 AM ----------

Code:
grep $LINE | find /opt/eir/var/tdr   is /Aldo/File*

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Scrutinizer; 04-15-2012 at 11:38 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Read input while another command is running &&

This script runs tshark, then displays the output. I want to read a keypress at all times throughout this script, especially during the 10 seconds that tshark is running. This code however, only takes input before tshark runs. #!/bin/bash main() { while (( "1" == "1" )) ; do keypress &&... (3 Replies)
Discussion started by: Kiah07
3 Replies

5. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

6. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

7. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

8. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

9. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

10. Solaris

Find & read a script in Unix

Hi, Please give me the cmd to find the location of a script(eg. xyz_bkup.sh).also i want to read the contents of the script. Thanks in advance James (8 Replies)
Discussion started by: James777
8 Replies
Login or Register to Ask a Question