0

My task is to count the number of names in a backup file I have made using wc and a pipe, display the first 5 names, then display the last 5 names. I have tested the 'strings' command to view the file, however wc will simply output a never ending blank line.

strings /mnt/tape/backup | wc -l

I am unsure if I should be looking for a specific section of the file. The output should be as follows;

109497

etc/dconf/db/distro.d/locks/10-authconfig-locks
lib
lib64
usr/lib64/libgcc_s-4.8.5-20150702.so.1
usr/lib64/libgcc_s.so.1

usr/lib/systemd/system/anaconda.target.wants/anaconda-nm-config.service
tmp/.X11-unix/X0
tmp/.esd-1000/socket
etc/fstab
root/.cache/abrt/lastnotification

Thank you.

1 Answers1

0

The command strings has too much excess data; more difficult to parse information from. The options -tf for xfsrestore shows a list of contents of the file.

#number of names
xfsrestore -tf /mnt/tape/backup | wc -w
110834

To determine the 1st and Last 5 lines of names, I parsed the -tf result int a .txt file I could safely modify.

xfsrestore -tf /mnt/tape/backup > test.txt

Then used VIM to view which line numbers were the first 5 names. $G drops to the bottom of the file for viewing the last 5 names. 22-26 and 110720-110724.

#display 1st 5 names
xfsrestore -tf /mnt/tape/backup | sed -n 22,26p

etc/pam.d/system-auth-ac
lib64
usr/lib64/libgcc_s-4.8.5-20150702.so.1
usr/lib64/libgcc_s.so.1
usr/share/locale/ast/LC_MESSAGES/grub.mo

#display last 5 names
xfsrestore -tf /mnt/tape/backup | sed -n 110720,110724p

etc/gshadow
etc/aliases.db
root/.local/share/recently-used.xbel
etc/fstab
etc/group