Results 1 to 3 of 3
I'm tring to create a bash script that removes text entries from text file 1
that are in file 2
text 1
Code:
abc
def
ghi
text 2
Code:
abc
...
- 12-24-2011 #1
filtering strings from text files
I'm tring to create a bash script that removes text entries from text file 1
that are in file 2
text 1
text 2Code:abc def ghi
my bash script so farCode:abc ghi
Code:#!/bin/bash cd /home/pouar/test index=0 # read text 1 while read line ; do a[$index]="$line" index=$(($index+1)) done < ./1 index=0 # read text 2 while read line ; do b[$index]="$line" index=$(($index+1)) done < ./2 n=$((0)) m=$((0)) x=${#a[*]} while ((n<x)) do if [ "${a[$n]}"="${b[$m]}" ]; then #if string in text 1 is equal to string in text 2 n=$(($n+1)); #go to next line in text 1 m=$(($m+1)) #go to next line in text 2 else # or else echo "${a[(($n))]}" #print string n=$(($n+1)) #go to next line in text 1 fi done
- 12-24-2011 #2
grep can read patterns from a file, that should do it.
Code:man grep
You must always face the curtain with a bow.
- 12-24-2011 #3


Reply With Quote