Need help in writing a script that do internal grep on a log file..and extract acct no's from it..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in writing a script that do internal grep on a log file..and extract acct no's from it..
# 1  
Old 09-20-2011
Question Need help in writing a script that do internal grep on a log file..and extract acct no's from it..

I need to write a script, which takes the input a log file and create output file with acct no's line by line from selected records with text like (in red) :
18:51:18 | 217863|Acct 0110855565|RC 17608| 16 Subs| 1596 UsgRecs| 2 Secs| 430 CPUms| prmis2:26213 <MoveUsage d
aemon needs to run on this account before it can be billed
.>
23:03:30 | 896529|Acct 2063947620|RC 17608| 8 Subs| 148 UsgRecs| 1 Secs| 280 CPUms| prbru6: 244 <MoveUsage d
aemon needs to run on this account before it can be billed
.>


The output file should only contain acct no's ( in bold ) line by line..
Smilie
Can any one help me out in this..Smilie
# 2  
Old 09-20-2011
Welcome to the forum.
Assuming the file format is fixed :
Code:
$ awk -F '[| ]' '{print $6}' file
0110855565
2063947620
$

Please use code tags next time.
# 3  
Old 09-20-2011
try this..

Code:
grep Acct <inputlogfile-name>| awk '{print $4}' | cut -f 1 -d "|" >> <outputfile-name>


Last edited by vbe; 09-20-2011 at 05:08 AM.. Reason: use code tags please
# 4  
Old 09-20-2011
You can try below

Code:
tput bold
awk -F "|" '{print $3}' file


Output:

Code:
Acct 0110855565
Acct 2063947620

Regards,
Haris
# 5  
Old 09-20-2011
Hi Anchal,
I need to send grep output of a log file as input to awk command..
I need to grep the log file like:
grep 'MoveUsage daemon needs to run on this account before it can be billed' <input Log File>
and this output of grep(which would be like):

18:51:18 | 217863|Acct 0110855565|RC 17608| 16 Subs| 1596 UsgRecs| 2 Secs| 430 CPUms| prmis2:26213 <MoveUsage d
aemon needs to run on this account before it can be billed.>
23:03:30 | 896529|Acct 2063947620|RC 17608| 8 Subs| 148 UsgRecs| 1 Secs| 280 CPUms| prbru6: 244 <MoveUsage d
aemon needs to run on this account before it can be billed.>

and from this output I need to extract only acct no's as I mentioned earlier..
# 6  
Old 09-20-2011
Code:
grep 'MoveUsage daemon needs to run on this account before it can be billed' <input Log File> | awk -F '[| ]' '$6 ~ /[0-9]{10}/ {print $6}'

# 7  
Old 09-20-2011
Hi anchal,
I ran the above suggested one,but it throwed error:

awk: syntax error near line 1
awk: bailing out near line 1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed / awk / grep to extract information from log

Hi all, I have a query that runs that outputs data in the following format - 01/09/12 11:43:40,ADMIN,4,77,Application Group Load: Name(TESTED) LoadId(5137-1-0-1XX-15343-15343) File(/dir/dir/File.T03.CI2.RYR.2012009.11433350806.ARD) InputSize(5344) OutputSize(1359) Rows(2) Time(1.9960)... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies

3. Shell Programming and Scripting

Script extract text from txt file with grep

All, I require a script that grabs some text from the gitHub API and will grep (or other function) for a string a characters that starts with (") quotes followed by two letters, may contain a pipe |, and ending with ) . What i have so far is below but it's not returning anything. ... (4 Replies)
Discussion started by: ChocoTaco
4 Replies

4. Shell Programming and Scripting

Shell Script to grep Job File name and Log File name from crontab -l

Hello, I am new to shell scripting. I need to write a shell script where i can grep the name of file ie. .sh file and log file from crontab -l. #51 18 * * * /home/oracle/refresh/refresh_ug634.sh > /home/oracle/refresh/refresh_ug634.sh.log 2>&1 #40 17 * * * /home/oracle/refresh/refresh_ux634.sh... (1 Reply)
Discussion started by: guptra
1 Replies

5. Shell Programming and Scripting

Need help to run query in loop for all acct nbr in a file..

I have a txt file with contents of acct nbr's like: 22222222222 33333333333 33445566778 I need to write a script which takes each acct nbr in the file and run the query like: select seq_nbr from event where acct_nbr='22222222222' and the query's output should be passed to a... (2 Replies)
Discussion started by: Rajesh Putnala
2 Replies

6. Shell Programming and Scripting

Need help to run query in loop for all acct nbr in a file..

I have a txt file with contents of acct nbr's like: 22222222222 33333333333 33445566778 I need to write a script which takes each acct nbr in the file and run the query like: select seq_nbr from event where acct_nbr='22222222222' and the query's output should be passed to a... (0 Replies)
Discussion started by: Rajesh Putnala
0 Replies

7. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

8. Shell Programming and Scripting

Script extract from log file

Hi i new to scripting and am trying to create a script to pull my current of logs from /var/logs/secure and name it securelog-Month-Day-Hour.txt example: grep 'Mar 5 11' /var/logs/secure > /home/(user)/Documents/Logs/mylog-02-1-11 How do i set the targeted strings to be the current... (2 Replies)
Discussion started by: M47H415
2 Replies

9. Shell Programming and Scripting

need a shell script to extract data from a log file.

If I have a log like : Mon Jul 19 05:07:34 2010; TCP; eth3; 52 bytes; from abc to def Mon Jul 19 05:07:35 2010; UDP; eth3; 46 bytes; from aaa to bbb Mon Jul 19 05:07:35 2010; TCP; eth3; 52 bytes; from def to ghi I will need an output like this : Time abc to def... (1 Reply)
Discussion started by: hitha87
1 Replies

10. Shell Programming and Scripting

shell-script which extract data from log file

give me a shell-script which extract data from log file on a server by giving date and time as input (for both start time and end time) and it will give the logs generated during the given time as output. (4 Replies)
Discussion started by: abhishek27
4 Replies
Login or Register to Ask a Question