Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
675 B
2
Indexable
Never
#!/bin/bash

# Check if a filename was provided as an argument
if [ $# -eq 0 ]
then
    echo "Error: No filename provided"
    exit 1
fi

# Check if the file exists
if [ ! -f $1 ]
then
    echo "Error: File does not exist"
    exit 1
fi

# Create a new file with the .txt extension
output_file="$(basename $1 .txt).new.txt"
touch "$output_file"

# Iterate over each line of the input file
while IFS= read -r line
do
    # Check if the line contains the . symbol
    if [[ $line = *"."* ]]
    then
        # If it does, append it to the new file
        echo "$line" >> "$output_file"
    fi
done < "$1"

echo "Created new file: $output_file"