grep first n and last n characters from a line in a file
You can use cut as:
Command:
cut --complement -c17-43 file1.txt
Output:
Mar 23 08:20:23 : 235
Mar 23 08:21:45 : 127
Mar 23 08:22:34 : 875
Mar 23 08:25:46 : 322
Mar 23 08:26:12 : 639
you can do something like this
awk '{print $1,$2,$3,":",$NF}' logfile
You can use sed
:
sed -r "s/^(.{15} ?).*(.{5})$/\1\2/" logfile
Per suggestions, I have made the first pattern accommodate single-digit days which may not be zero-padded, and use .*
for the middle pattern to be more flexible.