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 Answers 2

    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 

        You must log in to answer this question.

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.