Hi , I have a file with the below contents like serialno, userid and password. When am trying to fetch column 3 using awk its working except for the user id jij due to the password having "*" in between. How to retrieve the password.
echo $a --> not giving output and showing error as echo : No match
Note: for other user id giving the correct output and if i remove the "*" from the password its retrieving Qm6Pnw .
actually the column 2 value is not constant and it will vary based on different ids, so cant check with that particular id . Need to get the value if i fetched the userid and corresponding password
it's not a matterof the shell version. It's a matter of using double-quotes when doing var assignment and (more importantly) when echo-ing the variable value.
See my initial response with colored double-quotes.
Also there's no need to use cat - awk is quite happy with reading the supplied file to read.
I asked about the bash version because rogerben said he got an error, which doesn't happen to me with the same code
To assign the value to a variable I use the backtick and it works. Taking up your code
a=`awk '$2=="jij" {print $3}' testfile`
echo "$a"
I know, I just replaced the grep of the rogerben code with cat
In a standard shell you do not need extra "quotes" around $( ) or ` ` in an assignment like a=... but if you do it works okay.
In contrast, in csh an evaluation/substitution occurs even in an assignment, so you should try
set a="`awk -v v2s="${uid}" '$2==v2s {print $3}' testfile`"
I have seen bugs when there are too many quoting types nested - a recent tcsh should have most of them fixed.
And: the csh parser as such is buggy by design - even the latest tcsh is bug-compatible - for mission-critical please use a standard shell!
For all shell types: wrap a $expression in "quotes" when it appears in command arguments, for example the echo command: