0

I have this string where I want to search for a keyword and then return the following word.

"SELECT \"city\",\"temp_lo\",\"temp_hi\",\"date\" FROM schema_name.\"weather_7\""

I want to return "schema_name" and the only indicating text is the preceding "FROM " string.

Thanks

2

For exactly the setup given, try

sed 's/^.*FROM //; s/\..*$//' file
0

Assuming that schema_name consists of a sequence of word characters, if your grep supports Perl Compatible Regular Expressions (PCRE) you could use

grep -Po 'FROM\s+\K\w+'

Ex.

echo '"SELECT \"city\",\"temp_lo\",\"temp_hi\",\"date\" FROM schema_name.\"weather_7\""' |
  grep -Po 'FROM\s+\K\w+'
schema_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.