Format log data

I have hundreds of lines similar to this:

Oct 30 10:06:40 localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
Oct 30 10:06:40 localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0

i want to add a comma after the date, and then print the remaining text to the end of the line.

the preferred output should be:

Oct 30 10:06:40, localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
Oct 30 10:06:40, localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0

i tried:

tail -5 datafile | cut -d' ' -f1,2,3,4- 

and

tail -5 datafile | awk '{print $1" "$2" "$3","$NF}'

both of these are incomplete. can someone help me finish it off? i'd prefer the awk solution.

Try this :

awk '{$3=$3","}1' input_file
1 Like