[TriLUG] Need some help parsing a file
Kevin Hunter Kesling
hunteke at earlham.edu
Mon Dec 30 11:25:04 EST 2013
At 9:24pm -0500 Sun, 29 Dec 2013, Peter Neilson wrote:
> On Sun, 29 Dec 2013 21:13:17 -0500, Dewey Hylton wrote:
>> try this:
>>
>> cut -c40- < filename.txt
>
> Doesn't use sed, but it's better than mine.
As the path was guaranteed to start on column 40, I think cut is the
simplest, fastest, and most "correct" solution . However, as we're
still talking about it today however, I offer a couple more regex based
solutions:
# this anchors the match to the beginning, and removes the
# first 39 characters.
$ perl -pe "s/^.{39}//" < filename.txt
# Rather than blanket removing the first 39 characters,
# this matches for removal the 19+ characters of the date
# and time, and the 20+ characters of the size. Given the
# column alignment, I assume this would _not_ be necessary
# unless you have files larger than 10 TB. Hmm.
$ perl -pe "s/^\S{10}\s+\S{5} .M\s+\d\S+ //" < filename.txt
Cheers,
Kevin
More information about the TriLUG
mailing list