# -*- coding: utf-8 -*-
"""Challenge 3 - Hard Question-Khalid AlHarbi

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1_2HkSGM815VLsizjxyZBUmFIz5FEe2D8
"""

# Create a file 'file.txt' with the provided content for testing
file_content = """987-123-4567
123 456 7890
(123) 456-7890
555-555-5555
(555)555-5555
(111) 111-1111
222-222-2222
abc-def-ghij
123-45-6789
"""

file_path = "/content/file.txt"
with open(file_path, "w") as file:
    file.write(file_content)

file_path

import subprocess

# Define the grep command to find valid phone numbers
command = r"grep -E '^(\([0-9]{3}\) [0-9]{3}-[0-9]{4}|[0-9]{3}-[0-9]{3}-[0-9]{4})$' /content/file.txt"

# Execute the command
result = subprocess.run(command, shell=True, capture_output=True, text=True)

# Capture the output
output = result.stdout
output