LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2013, 10:06 AM   #1
ablanco20
LQ Newbie
 
Registered: Jul 2013
Posts: 1

Rep: Reputation: Disabled
convert log file to CSV


Hi

I need to conver a file to csv:

input file:

Wed Jan 16 00:00:44 2013
Acct-Status-Type = Interim-Update
User-Name = "eircom@eircom.net"
Event-Timestamp = "Jan 16 2013 00:00:44 GMT"
Acct-Delay-Time = 0
NAS-Identifier = "srl2.bras"
Acct-Session-Id = "0728458577"
NAS-IP-Address = 159.134.155.7
Class = "|01-8556774:13555982:ENETBMRFT:SRL20"
Service-Type = Framed-User
Framed-Protocol = PPP
Framed-Compression = None
Unisphere-Pppoe-Description = "pppoe 40:55:39:d5:36:95"
Framed-IP-Address = 83.70.182.189
Framed-IP-Netmask = 255.255.255.255
Unisphere-Ingress-Policy-Name = "pl-ip-set-be"
Calling-Station-Id = "SRL20 atm 4/1/03/04:8.35"
Acct-Input-Gigawords = 0
Acct-Input-Octets = 421388612
Acct-Output-Gigawords = 1
Acct-Output-Octets = 705365597
Unisphere-Input-Gigapackets = 0
Acct-Input-Packets = 3153319
Unisphere-Output-Gigapackets = 0
Acct-Output-Packets = 4428532
NAS-Port-Type = Ethernet
NAS-Port = 2952792599
NAS-Port-Id = "GigabitEthernet 11/0/0.340302583:3403-2583"
Acct-Authentic = RADIUS
Acct-Session-Time = 1285212
Timestamp = 1358294444
Request-Authenticator = Verified

Wed Jan 16 00:01:44 2013
Acct-Status-Type = Interim-Update
User-Name = "bbbbbb@eircom.net"
Event-Timestamp = "Jan 16 2013 00:00:45 GMT"
Acct-Delay-Time = 0
NAS-Identifier = "srl1.bras"
Acct-Session-Id = "0987398276"
NAS-IP-Address = 159.134.155.27
Class = "|01-8728723:73173007:ENETBMRNK:NMN20"
Service-Type = Framed-User
Framed-Protocol = PPP
Framed-Compression = None
Unisphere-Pppoe-Description = "pppoe 30:46:9a:31:5e:63"
Framed-IP-Address = 83.71.32.215
Framed-IP-Netmask = 255.255.255.255
Unisphere-Ingress-Policy-Name = "pl-ip-set-be"
Calling-Station-Id = "NMN20 atm 1/2/07/03:8.35"
Acct-Input-Gigawords = 0
Acct-Input-Octets = 738316279
Acct-Output-Gigawords = 0
Acct-Output-Octets = 3760056664
Unisphere-Input-Gigapackets = 0
Acct-Input-Packets = 3397361
Unisphere-Output-Gigapackets = 0
Acct-Output-Packets = 4149203
NAS-Port-Type = Ethernet
NAS-Port = 3221227126
NAS-Port-Id = "GigabitEthernet 12/0.340201654:3402-1654"
Acct-Authentic = RADIUS
Acct-Session-Time = 1285212
Timestamp = 1358294444
Request-Authenticator = Verified


output file:
date,User-Name,Framed-IP-Address
Wed Jan 16 00:00:44 2013,"eircom@eircom.net",83.70.182.189
Wed Jan 16 00:01:44 2013,"bbbbbb@eircom.net",83.71.32.215

many thanks in advance
Ablanco20
 
Old 07-23-2013, 10:07 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,167

Rep: Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890Reputation: 890
i would use awk.
 
1 members found this post helpful.
Old 07-23-2013, 03:01 PM   #3
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
I would use PERL.
Code:
$input_file_name = $ARGV[$0];
my @out;
  open (INFILE,"< " . $input_file_name) || die ("Can't open Input file $input_file_name");
  
  while ($line = <INFILE>) {
    chomp $line;
	 my ($param, $item) = split(/=/,$line);
if ($line eq "") { next; }
if ($item eq "") { push (@out, $param.","); }
if ($param eq "User-Name ") { push (@out, $item.","); }
if ($param eq "Framed-IP-Address ") { push (@out, $item."\n"); }
	}
print @out;
close (INFILE);
 
1 members found this post helpful.
Old 07-23-2013, 03:21 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 19,328

Rep: Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471Reputation: 4471
Quote:
Originally Posted by ablanco20 View Post
Hi
I need to conver a file to csv:
My question to you would be: where is this log file coming from? Some devices/programs have options to output their logs in different formats. If this log file is from a remote device, and you're using syslog-ng, have you looked at the csv-parser flag?

http://www.balabit.com/sites/default...rsers_csv.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert content of same file into CSV file say_hi_ravi Programming 3 09-14-2011 03:33 AM
how to convert a simplte text file into csv using awk script certteam Linux - General 1 09-15-2010 01:23 AM
convert columns to rows (tab separated file to csv) doug23 Programming 16 08-16-2009 10:14 PM
Convert a number on each line to CSV file OlRoy Programming 9 08-20-2008 12:05 PM
Convert into CSV file say_hi_ravi Programming 4 07-17-2008 04:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration