Extracting recording using egrep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting recording using egrep
# 1  
Old 10-09-2013
IBM Extracting recording using egrep

Hello,

Need help using egrep

file format:
test.gz
Code:
Date, time, , number 1, number 2, counter...
20130618,912154, ,009912345678,911111111111,10000, , ,abc
20130618,982148, ,009101373810,034028791952294,8999, , ,gh

Want to extract number1 OR number2 records in files based on a two or three digit country code.
example:
country code: 91
then output should be line containing number1 or number2 starting with 91. (cases 0091<number>, 091<number>, +91<number>,91<number> )

How to use regular expressions in egrep ? Search position after 3rd comma or 4th comma and check for country code. Please help. Thanks !!!

Last edited by Franklin52; 10-09-2013 at 11:06 AM.. Reason: Please use code tags
# 2  
Old 10-11-2013
You could try with the expression similar to this:-
Code:
grep "^[0-9]*,[0-9]*, ,009[19] inputfile

I think that this translates as:-
  • ^ - from start of line
  • [0-9] - the digits
  • * - repeated as many times as needed
  • , - the literal character which is your field separator
  • This is shown twice, then a space and the string starting 009 then either a 1 or a 9.

Does that get you started? You may need to use grep -E or egrep with the character | as a logical or between them if you want to have multiple options, e.g.:-
Code:
grep -E "^[0-9]*,[0-9]*, ,009[19]|^[0-9]*,[0-9]*, ,9[19]|^[0-9]*,[0-9]*, ,[0-9]*,009[19]|^[0-9]*,[0-9]*, ,[0-9]*,9[19] inputfile


I hope that this helps. I might have missed the point, so please show me some more input & expected results along with what you have tried & the output and I will see if we can refine it a bit.



Robin
Liverpool/Blackburn
UK
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 10-11-2013
Why not using awk ?

Code:
$ cat tst2
Date, time, , number 1, number 2, counter...
20130618,912154, ,009912345678,911111111111,10000, , ,abc
20130618,912154, ,009912345678,921111111111,10000, , ,abc
20130618,982148, ,009101373810,034028791952294,8999, , ,gh
$ CountryCode=92
$ awk -F, -vC="$CountryCode" '($4~"^[ 0]*"C)||($5~"^[ 0]*"C)' tst2
20130618,912154, ,009912345678,921111111111,10000, , ,abc
$ CountryCode=91
$ awk -F, -vC="$CountryCode" '($4~"^[ 0]*"C)||($5~"^[ 0]*"C)' tst2
20130618,912154, ,009912345678,911111111111,10000, , ,abc
20130618,982148, ,009101373810,034028791952294,8999, , ,gh
$

This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 10-11-2013
@Robin
Thanks a lot !!! Yes! this will defiantly help me to start.

---------- Post updated at 07:22 AM ---------- Previous update was at 07:21 AM ----------
@ctsgnb
Will try it... thanks a lot!
# 5  
Old 10-11-2013
How about
Code:
grep -E "^(.*,){3}[ 0+,]*91" file

This User Gave Thanks to RudiC For This Post:
# 6  
Old 10-11-2013
Smilie Whoa! RudiC What's all that?

It looks neat, but I will have to work it out. Smilie

It could be wonderful shorthand that I will be pleased to learn/use. Smilie



Thanks,
Robin
# 7  
Old 10-11-2013
This may be even better, as it makes the leading comma check compulsory for both fields:
Code:
grep -E "^(.*,){2}.*, *[0+]{,2}91" file


Last edited by RudiC; 10-12-2013 at 03:46 PM..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Recording stats for Comcast

The last few weeks I've had a problem with Comcast in San Francisco (anyone else sharing the same issue ? Please share !) During the late afternoon throughout early morning hours I see a high amount of dropped packets and increased latency when pinging my favorite destinations, like 8.8.8.8. ... (1 Reply)
Discussion started by: SandmanCL
1 Replies

2. OS X (Apple)

Any mac software for recording keystrokes

I'm trying to find a good keylogger that doesn't come with any viruses. It happens to me several times that my browser crashes when I am in article writing or some other thing, very annoying. Thus, I need a keylogger to keep all my keystroke recorded. I 'v tried some, like the Aobo Mac Keylogger,... (1 Reply)
Discussion started by: Bluerosen
1 Replies

3. Shell Programming and Scripting

recording command outputs in background

For example: % ls /store > list.txt % less list.txt % 1.txt % 2.txt I want to execute 'ls' in verbose and store the result in background to 'list.txt' so i dont have to execute another command just to view the contents of the 'list.txt' % ls /store > list.txt % 1.txt % 2.txt %... (2 Replies)
Discussion started by: jehrome_rando
2 Replies

4. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

5. Post Here to Contact Site Administrators and Moderators

My game scores are not recording

Hi. I scored 38 on the hex game and it would not record my score. Strange. (2 Replies)
Discussion started by: MokoMoko
2 Replies

6. Shell Programming and Scripting

Recording a UNIX Session

Hi All, I have a question regarding recording the unix sessions. I know the recording can be done using script comman, however i want to create a daily file of unix session. Also when i open multiple sessions how will the script multiple session. Please suggest some solutions also which file... (0 Replies)
Discussion started by: amitkhiare
0 Replies

7. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

8. IP Networking

Data recording on Network

Hello, I have been task to record data on the network between two computers. On one side I have a Solaris 8 computer and on the other side there is a VX/Works machine. The messages that come across are data messages using a UDP protocol on a dedicated IP address. Does Solaris have anything I can... (4 Replies)
Discussion started by: rtoba
4 Replies

9. UNIX for Dummies Questions & Answers

recording keystrokes in vi

What is the syntax for recording command in vi. If I want to repeat a command over and over. My file is 12/01/05,,adsmte,9,0,0 12/02/05,,adsmte,12,0,0 12/03/05,,adsmte,10,0,0 12/04/05,,adsmte,11,0,0 12/05/05,,adsmte,10,0,0 12/06/05,,adsmte,10,0,0 12/01/05,,tsmpc1,57,1,2... (5 Replies)
Discussion started by: reggiej
5 Replies
Login or Register to Ask a Question