0

is there a posibility to find a word in a file and than to copy the following word?

Example:

abc="def"
bla="no_need"
line_i_need="information_i_need"
still_no_use="blablabla"

so the third line, is exactly the line i need!

is it possible to find this word with shell orders?

thanks for your support

Lama Dingo
  • 123
  • 1
  • 11
  • possible duplicate of [linux: Extract one word after a specific word on the same line](http://stackoverflow.com/questions/17371197/linux-extract-one-word-after-a-specific-word-on-the-same-line) – tripleee May 25 '15 at 07:23
  • If that's your file format, you might consider whether you trust the data to be eval-safe. `source "$filename"; echo "$line_i_need"` is a security risk if the data can be influenced by untrusted sources, and a bug risk if the data isn't in genuine POSIX sh assignment format, but certainly easy. – Charles Duffy May 25 '15 at 15:06

3 Answers3

1

Using an awk with custom field separator it is much simpler:

awk -F '[="]+' '$1=="line_i_need"{print $2}' file
information_i_need

-F '[="]+' sets field separator as 1 or more of = or "

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Use grep:

grep file_name line_i_need

It will print:

line_i_need="information_i_need"
diogo
  • 69
  • 1
  • 8
0

This finds the line with grep an cuts the second column using " separator

 grep file_name line_i_need | cut -d '"' -f2