bash - exclude some characters from a file
hi,
I would like to print this file: Code:
anche Code:
anche it has to be clean of spaces etc... because after that I need to parse the file word by word I have done this: Code:
while read line; Code:
WORD TO SEARCH: a: Thank you |
Hi,
Code:
TRASFORMER=$( echo "$line" | tr "[:upper:]" "[:lower:]" | sed -e 's/\.//g' -e 's/\,//g' -e 's/\-//g' -e 's/ //g' ) Code:
sed -e 's/[.,- ]//g' Code:
TRANSFORMER="${line//[,.- ]/}" Code:
lower="${line,,}" Code:
sed: expression -e #1, character 5: command `s' not terminated Code:
sed s/:$WORD//g My guess is, the Code:
WORD=$( fgrep -w -i "$TRASFORMER" "$dictfile" ) |
you're right, the problem is that, while searching the word in dictfile, it finds the LAST word that contains 'a';
i.e. I search word a and it finds: whisky-a-gogo so how to solve it? thanks |
Well, you need a better matching pattern. Dash is not considered a "word" character, so grep -w foo will match "bar-foo-baz". If your "$dictfile" contains one word per line, with no leading/trailing whitespaces, you can match whole lines:
Code:
grep "^${WORD}$" |
thanks, it works great
|
All times are GMT -5. The time now is 11:59 AM. |