mxgong
asked on
Help Shell script
Hi All
I would like to write a shell script to retrieve a value.
for example: there is a string: "no of customer": 3
I need a shell script to retrieve "3".
Can anyone help me ? I am new in shell.
thanks
I would like to write a shell script to retrieve a value.
for example: there is a string: "no of customer": 3
I need a shell script to retrieve "3".
Can anyone help me ? I am new in shell.
thanks
ASKER
Hi Papertrip
Thanks for your reply, but this is not file.
It's the result of the command.
eg: /usr/lib/result.sh, then I got the "no of customer": 3
But I need a shell script for retrieving "3" from the result.
Thanks
Thanks for your reply, but this is not file.
It's the result of the command.
eg: /usr/lib/result.sh, then I got the "no of customer": 3
But I need a shell script for retrieving "3" from the result.
Thanks
ASKER
The result from command will be:
{
"no of customer": 3
}
{
"no of customer": 3
}
try this
grep "no of customer" filename | awk -F: '{ print $2 }'
grep "no of customer" filename | awk -F: '{ print $2 }'
#!/bin/bash
/usr/lib/result.sh | grep '^\"' | awk -F ': ' '{print $2}'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks Papertrip
the output is: [space]3
there is a whitespace before 3, is it able to remove the space?
Thanks
the output is: [space]3
there is a whitespace before 3, is it able to remove the space?
Thanks
[root@broken ~]# cat asdf
"blah": a
"blah": b
[root@broken ~]# grep '^"' asdf |awk -F': ' '{print $2}'
a
b
[root@broken ~]#
ASKER
Thanks it works fine now.
Regards
Regards
ASKER
perfect, thanks
Open in new window
That will print the 2nd field using : as a delimiter of each line in filename.Really depends on what else is in the file you are parsing.