Sponsored Content
Top Forums Shell Programming and Scripting parsing log files, removing spaces and replace with commas Post 302323719 by ghostdog74 on Monday 8th of June 2009 08:09:32 PM
Old 06-08-2009
if you have Python
Code:
#!/usr/bin/env python
for line in open("file"):
    line=line.strip()
    st = line.index("[")
    line=line.replace("]","],")
    o = line[:st].split()
    print ' '.join(o[:2]),','.join(o[2:]),line[st:]

output
Code:
# ./test.py
Jun 5 08:40:02,SunNiprS1,usba: [ID 349649 kern.info], PLEXTOR Corp. USB Storage Adapter 004400947B
Jun 5 08:40:02,SunNiprS1,genunix: [ID 936769 kern.info], scsa2usb0 is /pci@1e,600000/usb@a/cdrom@2
Jun 5 08:40:02,SunNiprS1,genunix: [ID 408114 kern.info], /pci@1e,600000/usb@a/cdrom@2 (scsa2usb0) online
Jun 5 08:41:09,SunNiprS1,scsi: [ID 193665 kern.info], sd16 at scsa2usb0: target 0 lun 0
Jun 5 08:41:09,SunNiprS1,genunix: [ID 936769 kern.info], sd16 is /pci@1e,600000/usb@a/cdrom@2/disk@0,0
Jun 5 08:41:35,SunNiprS1,genunix: [ID 408114 kern.info], /pci@1e,600000/usb@a/cdrom@2/disk@0,0 (sd16) online


Last edited by ghostdog74; 06-09-2009 at 12:47 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

removing commas from text file

Dear all I have a file which looks like this xxxxxxxxxxxxxx,xxx,xxxxxxxxxx xxxxxxxxxxxxxx,xxx,xxxxxxxxxx etc basically 14 characters then a comma, three characters, then a comma then 10 characters. We are uploading this file to our mainframe and they want the commas removed, so it... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

2. Shell Programming and Scripting

Removing trailing spaces from delimited files

Hi All I have a file of the following format (delimited by |) this is field 1 | field 2 (lots of blank spaces) | field 3 (lots of blank space) | field 1 | more text (lots of blank spaces) | dhjdsk | Is there a way I can remove... (6 Replies)
Discussion started by: djkane
6 Replies

3. Programming

Removing empty spaces and adding commas

I have a file which contains numbers as follows: 1234 9876 6789 5677 3452 9087 4562 1367 2678 7891 I need to remove the empty spaces and add commas between the numbers like: 1234,9876,6789,5677,3452, 9087,4562,1367,2678,7891 Can anyone tell me the command to do... (4 Replies)
Discussion started by: jazz
4 Replies

4. Linux

How do i remove commas(,) & spaces

Hey guys, I am very much new to shell scripts. So you ppl may feel that i am asking stupid question here. :D 1. I am using command line argument as an input variable. The user gets this value in his mail from client which has commas n spaces (Eg. 12,34,56,789) and the scripts... (5 Replies)
Discussion started by: anushree.a
5 Replies

5. Shell Programming and Scripting

Need help in removing commas

i have the below line as output from a script. I want to delete the string "," and get the output without comma, cat D* | grep "bytes free" | awk '{print $3}' | ????? output: 40,966,189,056 Desired O/P: 40966189056 (1 Reply)
Discussion started by: ali560045
1 Replies

6. Shell Programming and Scripting

Help with sed and replacing white spaces with commas

Dear all, I am in a bit of a quandary. I have 400 text files which I need to edit and output in a very specific way. Here is a sample text file copied from gedit ... The columns will come out a bit messed up but when I cat <file>, it gives a table with six columns (0-28, tot lob vol, vcsf,... (6 Replies)
Discussion started by: antonz
6 Replies

7. UNIX for Dummies Questions & Answers

Removing blank spaces from text files in UNIX

Hello, I am an super newbie, so forgive my sheer ignorance. I have a series of text files formatted as follows (just showing the header and first few lines): mean_geo mean_raw lat lon 0.000 0 -70.616 163.021 0.000 0 -70.620 163.073 0.000 ... (8 Replies)
Discussion started by: vtoniolo
8 Replies

8. Shell Programming and Scripting

Help with removing additional commas in string

Hi Experts, I have below strings hello,hi,,,,,,start date age,code,,,,,61,season I am trying to format this string to hello,hi,start date age,code,61,season Can anyone please help me in achieving this? Kind Regards, RB (3 Replies)
Discussion started by: ramakanth_burra
3 Replies

9. Shell Programming and Scripting

Removing just the trailing commas :-(

Hi all, I haven't needed to do any shell based editing for nearly 20 years, and no amount of searching around has found me a solution to this very simple problem :-( I have a csv file. Some lines have three commas at the end. This means the invoice hasn't been paid. I'd like to use sed / grep... (4 Replies)
Discussion started by: chardyzulu
4 Replies

10. UNIX for Beginners Questions & Answers

Removing commas from CSV file

Hi I'm creating a sh script to generate a csv file. The CSV contains the values from a sql table. The content looks this: a,b,c,c2,c3,,,,,,,,,,,d,e I have some code that can separate the fields using the comma as delimiter, but some values actually contain commas, such as... (2 Replies)
Discussion started by: preema
2 Replies
TIMECOUNTERS(4) 					   BSD Kernel Interfaces Manual 					   TIMECOUNTERS(4)

NAME
timecounters -- kernel time counters subsystem SYNOPSIS
The kernel uses several types of time-related devices, such as: real time clocks, time counters and event timers. Real time clocks are responsible for tracking real world time, mostly when the system is down. Time counters are responsible for tracking purposes, when the sys- tem is running. Event timers are responsible for generating interrupts at a specified time or periodically, to run different time-based events. This page is about the second. DESCRIPTION
Time counters are the lowest level of time tracking in the kernel. They provide monotonically increasing timestamps with known width and update frequency. They can overflow, drift, etc and so in raw form can be used only in very limited performance-critical places like the process scheduler. More usable time is created by scaling the values read from the selected time counter and combining it with some offset, regularly updated by tc_windup() on hardclock() invocation. Different platforms provide different kinds of timer hardware. The goal of the time counters subsystem is to provide a unified way to access that hardware. Each driver implementing time counters registers them with the subsystem. It is possible to see the list of present time counters, via the kern.timecounter sysctl(8) variable: kern.timecounter.choice: TSC-low(-100) HPET(950) i8254(0) ACPI-fast(900) dummy(-1000000) kern.timecounter.tc.ACPI-fast.mask: 16777215 kern.timecounter.tc.ACPI-fast.counter: 13467909 kern.timecounter.tc.ACPI-fast.frequency: 3579545 kern.timecounter.tc.ACPI-fast.quality: 900 kern.timecounter.tc.i8254.mask: 65535 kern.timecounter.tc.i8254.counter: 62692 kern.timecounter.tc.i8254.frequency: 1193182 kern.timecounter.tc.i8254.quality: 0 kern.timecounter.tc.HPET.mask: 4294967295 kern.timecounter.tc.HPET.counter: 3013495652 kern.timecounter.tc.HPET.frequency: 14318180 kern.timecounter.tc.HPET.quality: 950 kern.timecounter.tc.TSC-low.mask: 4294967295 kern.timecounter.tc.TSC-low.counter: 4067509463 kern.timecounter.tc.TSC-low.frequency: 11458556 kern.timecounter.tc.TSC-low.quality: -100 The output nodes are defined as follows: kern.timecounter.tc.X.mask is a bitmask, defining valid counter bits, kern.timecounter.tc.X.counter is a present counter value, kern.timecounter.tc.X.frequency is a counter update frequency, kern.timecounter.tc.X.quality is an integral value, defining the quality of this time counter compared to others. A negative value means this time counter is broken and should not be used. The time management code of the kernel chooses one time counter from that list. The current choice can be read and affected via the kern.timecounter.hardware tunable/sysctl. SEE ALSO
attimer(4), eventtimers(4), ffclock(4), hpet(4) BSD
April 12, 2014 BSD
All times are GMT -4. The time now is 02:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy