-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomm.sh
More file actions
40 lines (34 loc) · 831 Bytes
/
comm.sh
File metadata and controls
40 lines (34 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Check if both files are provided as input
if [ $# -ne 2 ]; then
echo "Error: Please provide two file names as arguments"
exit 1
fi
# Check if the first file exists
if [ ! -f "$1" ]; then
echo "Error: $1 does not exist"
exit 1
fi
# Check if the second file exists
if [ ! -f "$2" ]; then
echo "Error: $2 does not exist"
exit 1
fi
# Read the first file line by line
while read line1
do
# Ignore empty lines
if [[ -n "$line1" ]]; then
# Read the second file line by line
while read line2
do
# Ignore empty lines
if [[ -n "$line2" ]]; then
# Compare the lines
if [[ "$line1" == "$line2" ]]; then
echo "$line1"
fi
fi
done < "$2"
fi
done < "$1"