简体   繁体   中英

Egrep over multiple lines in a bash script function

I have a function to check a file against multiple long strings seperated by pipes. I want to put each string in the script on a new line so it's more readable. I've tried adding backslashes to the end of each line but they're just caught within the grep statement.

my_function () {
sudo zcat my_file.gz |
egrep -c 'my_long_string_1 |
my_long_string_2 |
my_long_string_3'
}

This does output a result, however, it's incorrect.

Use egrep like this on multiple lines:

my_function () {
   sudo zcat my_file.gz |
   egrep -c "my_long_string_1|\
   my_long_string_2|\
   my_long_string_3"
}

Make sure there is no space before or after backslash and there is no space on new lines before each pattern of egrep.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM