determination of regexp position in a file
2011-05-13 12:00
[ZL]
We sometimes need to determinate the position of a certain regexp in a file using simple unix commands.
Here comes an easy way for that:
(This example works until 999999 lines, if you need more, please adjust -B value.)
Here comes an easy way for that:
grep -B999999 'regexp' <filename> | wc -l
(This example works until 999999 lines, if you need more, please adjust -B value.)
skipping first line from file
2011-03-28 12:00
[ZL]
Skipping first line from a small size text file
more +2 filename
For file more than one page:
tail +2 filename
first weekday of the month
2011-03-23 12:00
[ZL]
It is easy to get the desired weekday of the next month in PostgreSQL 8.3+. For example let us get the first Tuesday:
extract('dow' from date_string): returns the week numbering of the day (0=Sunday, 9=Saturday), Tuesday=2
CASE WHEN ... THEN ... ELSE ... END: testing of negative number when shifting days. It is because we would like to prevent code from shifting back to previous month. If negative value detected then we add extra 7 days.
date_trunc('month', date_string): truncate the date with keeping month and larger entities (years in this case)
SELECT
CASE WHEN (2 - extract('dow' FROM date_trunc('month', now() + interval '1 month'))) < 0
THEN 9 - extract('dow' FROM date_trunc('month', now() + interval '1 month'))
ELSE 2 - extract('dow' FROM date_trunc('month', now() + interval '1 month'))
END * interval '1 day' + date_trunc('month', now()) + interval '1 month' AS next_tue
Explanation:extract('dow' from date_string): returns the week numbering of the day (0=Sunday, 9=Saturday), Tuesday=2
CASE WHEN ... THEN ... ELSE ... END: testing of negative number when shifting days. It is because we would like to prevent code from shifting back to previous month. If negative value detected then we add extra 7 days.
date_trunc('month', date_string): truncate the date with keeping month and larger entities (years in this case)
awk round()
2011-02-23 12:00
[ZL]
Round float values in 'awk':
# cat some.txt | awk '{ printf "%.0f", $1; }'
Linux blkid
2011-02-18 12:00
[ZL]
Messed up disks/partitions in Linux?
# blkid /dev/sdb1
/dev/sdb1: UUID="b9be1356-bc62-4bd5-9d76-e4a6da922c36" TYPE="reiserfs"
tells about their original UUIDs.

[magyar]