Extract Programs from Command History

LinuxBeginner
Practice Now

Introduction

A small history export stores a record number and a program name on each pipe-delimited line. An analyst needs only the program field for a later report.

This challenge applies field extraction from the pipeline lab and file redirection from the stream lab to one simple artifact.

Extract the Program Field

Current Situation

/home/labex/project/history-analysis/command-history.txt contains five records. Each line has a history number in field 1 and a program name in field 2, separated by |.

Scope

  • Extract field 2 from every record.
  • Keep the original record order and repeated names.
  • Save the result as programs.txt.

Your Goal

Create one file containing the five program names, one per line.

Acceptance Criteria

  • programs.txt contains exactly one field-2 value for each source record.
  • History numbers and delimiter characters are absent.
  • The source order and repeated ls entry are preserved.

Hints

Which field tool applies?

The pipeline lab used cut with a chosen delimiter and field number. Redirect that command's standard output to the required file.

Summary

You extracted one delimited field and saved it with standard-output redirection.

✨ Check Solution and Practice