Need help cutting a couple of fields from log file.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help cutting a couple of fields from log file.
# 1  
Old 03-18-2008
Need help cutting a couple of fields from log file.

Data begins as such;

Mar 16 03:27:05 afzpimdn01 named[221]: [ID 295310 daemon.notice] denied update from [1nn.nn.9].3983 for "nnn.nnn.in-addr.arpa" IN
Mar 16 03:27:37 afzpimdn01 named[221]: [ID 295310 daemon.notice] denied update from [1nn.nnn.nn.53].4844 for "nnn.nnn.in-addr.arpa" IN
Mar 16 03:27:56 afzpimdn01 named[221]: [ID 295310 daemon.notice] denied update from [1nn.nnn.nn.52].2650 for "nnn.nnn.in-addr.arpa" IN

cut -d "" -f 12,14 filename > filename2

gives me;

[1nn.nnn.nn.9].3983 "nnn.nnn.in-addr.arpa"
[1nn.nnn.nn.53].4844 "nnn.nnn.in-addr.arpa"
[1nn.nnn.nn.52].2650 "nnn.nnn.in-addr.arpa"

I need to remove the "[" , "]" and the port number ".3983", ".4844' from field 1 and the double quotes from field 2, then I will sort -u the output to a new filename.

I am looking to get;

1nn.nnn.nn.9 nnn.nnn.in-addr.arpa
1nn.nnn.nn.52 nnn.nnn.in-addr.arpa
1nn.nnn.nn.53 nnn.nnn.in-addr.arpa

I have not been able to get the substituions with sed.

Thanks for any advice or direction,

Altamaha
# 2  
Old 03-18-2008
Code:
vnix$ sed 's/^\[//;s/\][^"]*"/ /;s/"$//' <<HERE
> [1nn.nnn.nn.9].3983 "nnn.nnn.in-addr.arpa"
> [1nn.nnn.nn.53].4844 "nnn.nnn.in-addr.arpa"
> [1nn.nnn.nn.52].2650 "nnn.nnn.in-addr.arpa"
> HERE
1nn.nnn.nn.9 nnn.nnn.in-addr.arpa
1nn.nnn.nn.53 nnn.nnn.in-addr.arpa
1nn.nnn.nn.52 nnn.nnn.in-addr.arpa

era
# 3  
Old 03-18-2008
Many thanx.

Using cat filename | sed 's/^\[//;s/\][^"]*"/ /;s/"$//' > filename2 gives me the exact output I was needing.

I will now try to see if I can place my "cut" and your "sed" into a single script that user can run each day.

Thanks again,
Altamaha
# 4  
Old 03-18-2008
As you should well know, your cat is a Useless Use.

Code:
cut -d "" -f 12,14 |
sed 's/^\[//;s/\][^"]*"/ /;s/"$//'

That's all it takes to combine them.
era
# 5  
Old 03-19-2008
era,

You are right... useless now.

At the time I posted, I did not know how to get the data stream into the script. Since I had previously used a grep of the message log to create a temp file, I used the cat to get the temp file into the sed.

I now have it as folows;

grep "denied update" /var/adm/messages | cut -d" " -f 12,14 |sed 's/^\[//;s/\][^"]*"/ /;s/"$//' | sort -u >tempfile

I thank you for you answers to my questions, and your help in directing me.

Altamaha
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cutting pattern from source file

hi gurus, I want to cut a selected pattern from the source file For example <operation > Update Update Update <operation> I want to select the three lines having update and the one above <operation> to be cut from source file and paste it to another As of now i... (2 Replies)
Discussion started by: r_t_1601
2 Replies

2. Shell Programming and Scripting

Cutting fields from lines with multiple spaces

Please see the following code, between "status" and "OK" exists many spaces, I want to get status OK . how to ignore multi spaces? If tab exists in the spaces, how to ignore it ? Is there other commands can replace cut? $ echo 'drv status OK'| cut... (3 Replies)
Discussion started by: 915086731
3 Replies

3. UNIX for Advanced & Expert Users

Add a Couple of Carriage returns to text file

I have a directory of over a hundred text files that I'm getting ready to merge with the CAT command. However there is only one space after each file; this makes the output look crowded. I would like to add two, possibly even four carriage returns at the end of each text file to make the final... (2 Replies)
Discussion started by: tg3793
2 Replies

4. Shell Programming and Scripting

Cutting file name from end

Dear Friends, I want to take last 10 characters of a file name in a variable. E.g. file name is 123432311234567890.txt then we want "1234567890" to be taken in an variable. Request you to guide me to do the same Thanks in anticipation Anushree (7 Replies)
Discussion started by: anushree.a
7 Replies

5. Shell Programming and Scripting

Cutting specific lines from a file

Hi, I have a file named Mani.txt. The contents are like this cat Mani.txt -------------------------------------------------------- Hi there how r u My Name is Mani Bye ------------------------------------------------------------ I want to cut the first and last lines from the file... (15 Replies)
Discussion started by: pathanjalireddy
15 Replies

6. Shell Programming and Scripting

Cutting last few characters of file name

Dear Friends, Here I have two queries. 1. Want to make folder named as last three characters of a file name (length of file name can vary file to file) E.g File name is AAAACCCCBBBB.txt (12 Characters excluding file extension) then folder to be created is BBB Irrespective of... (7 Replies)
Discussion started by: anushree.a
7 Replies

7. Shell Programming and Scripting

cutting fields and doing trim in awk

hi, I have this code: #!/usr/bin/ksh #SERVICES gzcat *SERVICES* | awk ' { SUBSCRIBERNUMBER=substr($0,1,20) SUBSCRIBERNUMBER=trim(SUBSCRIBERNUMBER) SERVICECODE=substr($0,22,61) SERVICECODE=trim(SERVICECODE) STARTDD=substr($0,63,72) STARTDD=trim(STARTDD) STARTDT=substr($0,74,81)... (1 Reply)
Discussion started by: naoseionome
1 Replies

8. Shell Programming and Scripting

cutting a section of a big file

Hi, I have a text file 10giga size. Opening the file with vi takes forever ... Im intersting only with the 100 first records. Is there way to copy those 100 lines to new file (with no need to open the file)? Thanks (6 Replies)
Discussion started by: yoavbe
6 Replies

9. Shell Programming and Scripting

Cutting a large log file in to smaller ones

I have a very large (150 megs) IRC log file from 2000-2001 which I want to cut down to individual daily log files. I have a very basic knowledge of the cat, sed and grep commands. The log file is time stamped and each day in the large log file begins with a "Session Start" string like so: ... (11 Replies)
Discussion started by: MrTangent
11 Replies

10. UNIX for Dummies Questions & Answers

Cutting n consecutive lines from a file...

Hi, I have this problem of separating 10 consecutive lines from a file, say starting from 21 to 30... I have used a filter like this.. head -n 30 myfile | tail -n 10 Is there a simpler way than this? (2 Replies)
Discussion started by: Vishnu
2 Replies
Login or Register to Ask a Question