How can I read specific line and specific field using Bash?

How about! /bin/bash grep 'testme=' /var/tmp/test. Ini | awk -F= '{ print $2 } or alternatively just using bash!

/bin/bash regex='testme=(.*)' for I in $(cat /var/tmp/test. Ini); do if $i =~ $regex ; then echo ${BASH_REMATCH1} fi done.

How about #! /bin/bash grep 'testme=' /var/tmp/test. Ini | awk -F= '{ print $2 }' or alternatively just using bash #!

/bin/bash regex='testme=(.*)' for I in $(cat /var/tmp/test. Ini); do if $i =~ $regex ; then echo ${BASH_REMATCH1} fi done.

There is almost never a need to pipe the output of grep to awk. Just use awk directly: awk -F= '/testme=/{ print $2 }' – William Pursell Oct 18 at 10:12.

I checked your codes, the problem is in your for loop. You actually read each line of the file, and give it to grep, which is NOT correct. I guess you have many lines with error, no such file or directory (or something like that).

You should give grep your file name. (without the for loop) e.g. Grep "testme=" /var/tmp/test.ini.

Grep -v '^;' /tmp/test. Ini | awk -F= '$1=="testme" {print $2}' The grep removes comments, then awk finds the variable and prints its value. Or, same thing in a single awk line: awk -F= '/^\s*;/ {next} $1=="testme" {print $2}' /tmp/test.ini.

$ grep '^testme=' /tmp/test. Ini | sed -e 's/^testme=//' value1 We find the line and then remove the prefix, leaving only the value. Grep does the iterating for us, no need to be explicit.

Would be simplier: sed "/^testme=/ s@^testme=@@" /tmp/test. Ini – uzsolt Oct 17 at 14:18.

Awk is probably the right tool for this, but since the question does seem to imply that you only want to use the shell, you probably want something like: while IFS== read lhs rhs; do if test "$lhs" = testme; then # Here, $rhs is the right hand side of the assignment to testme fi done.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions