Artificial intelligent assistant

Extract lines from text with string as input How can extract lines that match the regexp string `^li` **from the text (not a file)** below using `sed` or something? linux loan litmus launch I tried `grep` but I couldn't find a way to search within a quoted text, not a text file. grep -n -i "^li" "linux loan litmus launch" Returns `No such file or directory`. And I don't want to save this text as a file before searching, if possible.

You need to use a herestring (`<<<`) here to pass the string as input to `grep`, herestring returns a file descriptor, `grep` can then operate on that:


$ grep -ni "^li" <<<"linux
loan
litmus
launch"


**Output:**


1:linux
3:litmus


If your shell doesn't support herestrings, many shells don't, you can print your string and pipe it to `grep`:


$ echo "linux
loan
litmus
launch" | grep -n -i "^li"
1:linux
3:litmus


Or use heredoc (`<<`):


$ grep -ni "^li" < > linux
> loan
> litmus
> launch
> EOF
1:linux
3:litmus

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 52ae2b916c902f7d38c76054a748b070