Skip to content

Instantly share code, notes, and snippets.

@abadger
Created October 11, 2022 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abadger/b3103a4c3d5bb82b52590def7f0eadc9 to your computer and use it in GitHub Desktop.
Save abadger/b3103a4c3d5bb82b52590def7f0eadc9 to your computer and use it in GitHub Desktop.
Some string exercises
(1)
Write a small program that uses "string.format() to print a greeting card message to all the following people:
Toshio
Andrew
Rodolfo
(2)
Here is a snippet from a log file:
log_message = """
Oct 9 00:00:51 camelback systemd[7500]: Starting audit...
Oct 9 00:00:18 camelback systemd[1]: logrotate.service: Deactivated successfully.
Oct 9 00:00:18 camelback systemd[1]: Finished Rotate log files.
Oct 9 00:00:18 camelback audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=logrotate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Oct 9 00:00:18 camelback audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=logrotate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Oct 9 00:00:18 camelback audit: BPF prog-id=0 op=UNLOAD
Oct 9 00:00:19 camelback systemd[1]: mlocate-updatedb.service: Deactivated successfully.
Oct 9 00:00:19 camelback systemd[1]: mlocate-updatedb.service: Consumed 1.459s CPU time.
Oct 9 00:00:19 camelback audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=mlocate-updatedb comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Oct 9 00:00:19 camelback audit: BPF prog-id=0 op=UNLOAD
Oct 9 00:00:50 camelback krunner[1683939]: 56131.758 Info AppManagerStates.cpp:1903: Saving finished
Oct 9 00:00:50 camelback krunner[1683939]: Restarted systemd
Oct 9 00:00:51 camelback systemd[7500]: Starting Update git repos...
Oct 9 00:00:51 camelback systemd[7500]: Starting Update vim plugins...
"""
Can you write a program that counts how many lines are from
systemd, audit, and krunner?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment