a bashscript which finds duplicate lines and lists their frequency
- User
a bashscript which finds duplicate lines and lists their frequency
Assistant
Here's a simple bash script that finds duplicate lines in a file and lists their frequency:
#!/bin/bash # Check if the file exists if [ ! -f "$1" ]; then echo "Error: Please provide a valid file." exit 1 fi # Read the file line by line while read line; do # Increment the count of the line if it already exists in the array if [[ -n "${duplicate_lines[${line}]}" ]]; then ((duplicate_lines[${line}]++)) else # Add the line to the array with a count of 1 duplicate_lines[${line}]=1 fi done < "$1" # Print the duplicate lines and their frequencies for line in "${!duplicate_lines[@]}" do echo "${line}: ${duplicate_lines[${line}]}" done | sort -rnSave this script to a file named
find_duplicate_lines.sh, and make it executable with the following command:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.