grep lines that start with a specific string
问题 I want to find all the lines in a file that start with a specific string. The problem is, I don't know what's in the string beforehand. The value is stored in a variable. The naïve solution would be the following: grep "^${my_string}" file.txt; Because if the Bash variable my_string contains ANY regular expression special characters, grep will cry, and everyone will have a bad day. You don't want to make grep cry, do you? 回答1: You should use awk instead of grep for non-regex search using