Select ip and date using sed or gawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select ip and date using sed or gawk
# 1  
Old 11-09-2009
Select ip and date using sed or gawk

Code:
1.56.253.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.6.253.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.65.253.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.65.253.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.63.53.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.65.253.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.16.23.48 - - [09/Nov/2009:07:02:24 +0100] "GET "
1.64.25.48 - - [09/Nov/2009:07:02:24 +0100] "GET "


need command which give the output

1.6.253.48 - 09/Nov/2009:07:02:24
1.65.253.48 - 09/Nov/2009:07:02:24
1.63.53.48 - 09/Nov/2009:07:02:24
1.16.23.48 - 09/Nov/2009:07:02:24
1.64.25.48 - 09/Nov/2009:07:02:24
# 2  
Old 11-09-2009
Code:
awk -F'[ \t[]*' '{print $1,$2,$4}'

# 3  
Old 11-09-2009
Code:
$ awk '{print $1,$4}' file

# 4  
Old 11-09-2009
Hi,

Assuming the contents are saved in a file "saved_data", you can try the following.

Code:
cat saved_data | tr "+" "-" | cut  -d"-" -f1,3

You can easily remove the square brackets as well using tr.
# 5  
Old 11-09-2009
Quote:
Originally Posted by ggs
Hi,

Assuming the contents are saved in a file "saved_data", you can try the following.

Code:
cat saved_data | tr "+" "-" | cut  -d"-" -f1,3

You can easily remove the square brackets as well using tr.
no need cat.
# 6  
Old 11-09-2009
Thanks. I need uniq entries based on ip address
# 7  
Old 11-09-2009
That is not possible with your input file since there are multiple entries with the same IP-address. Perhaps you mean you would like to have it sorted?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

Hi All, <Re-posting in Correct group> I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful.... Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
Discussion started by: Satya C1
6 Replies

2. Shell Programming and Scripting

Gawk and sed question

Can anyone tell me what this script does? sort file1.txt | awk -F, -f event.gawk Thank you. (2 Replies)
Discussion started by: dee campbell
2 Replies

3. Shell Programming and Scripting

Sed for select and retrieve data

I would like to recover the data from 3 text tags. These three markers are located between the tags specific location <tag1> and </tag1> knowing that they are in many places. In File.txt: <tag2>txt2</tag2> <tag3>txt3</tag3> <tag4>txt4</tag4> .... <tag1> <tag2>txt2</tag2>... (3 Replies)
Discussion started by: Amad
3 Replies

4. UNIX for Dummies Questions & Answers

Select text between current date and output to new txt file

Hi guys, brand new to this thread and very very new to UNIX...so go easy please! Anyway I have a file that looks like this: >>-------------------------------------------------------------------------- Date/Time/Eng. : 2012-06-22 / 00:26 / DS Reported problem : (SD) ... (5 Replies)
Discussion started by: martin0852
5 Replies

5. Windows & DOS: Issues & Discussions

Extracting variables between commas : GAWK or SED

Hello, I need some help, I got a CSV file called test.txt with this text in it : 08/02/2011;0,677;0,903;1,079;1,336;1,513;1,683 There's only a line and i need to copy theese numbers into variables : 0,677 0,903 1,079 1,336 1,513 1,683 The output file should look like this... (5 Replies)
Discussion started by: jujulips
5 Replies

6. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

7. Shell Programming and Scripting

SED scripting select

Say I have a file 'example.txt' with these lines of code in it: hello:anddasd:cheese:gerg whatever:sdadsa:asdfasdfa:wwew hmmmm:something:gfhfhgf:sdasdas Question: 1. How would I write a script which is able to take all the words before the first ':'? 2. How would I write a script which is... (6 Replies)
Discussion started by: i_am_a_robot
6 Replies

8. Shell Programming and Scripting

How to find date Difference in AWK/GAWK with millisecond precision

Hi, I have a log file that has the date in this format "2006-05-30_13:14:04,256". I need to find the time difference between two log entries in milliseconds. How to achieve this in AWK/GAWK script? :confused: (2 Replies)
Discussion started by: omprasad
2 Replies

9. Shell Programming and Scripting

Out put with select date. Help !!!

If I have a flatfile like vote.dat NAME | SEX | DATETIME | VOTE Jason|M|2005-12-10 08.01.30|Y Benson|M|2005-12-10 12.01.00|Y William|M|2005-12-10 08.01.09|Y Nick|M|2005-12-11 09.01.07|Y Pascal|M|2005-12-11 01.01.06|Y Mickey|F|2005-12-12 12.01.30|Y How can I write a korn script to have... (4 Replies)
Discussion started by: sabercats
4 Replies
Login or Register to Ask a Question