Guys How can I make this work
`find /xyz/abc/music/ |grep def`
I don't want to store the array in any temporary variable. How can we directly operate on this array.
so to get the 1st element of that array
echo ${$(`find /xyz/abc/music/ |grep def`)[0]} Please help me How I can achieve this
You can use: targets=($(grep -HRl "pattern" .)) Note use of (...) for array creation in BASH. Also you can use grep -l to get only file names in grep 's output (as shown in my command).
grep( array, function [, invert ] )Returns: Array. Description: Finds the elements of an array which satisfy a filter function.
The -n option of the “grep” command is used to print the output of the search string with the line number of the file.
The grep command searches a text file based on a series of options and search string and returns the lines of the text file which contain the matching search string.
Put the call to find in array brackets
X=( $(find /xyz/abc/music/ | grep def) )
echo ${X[1]}
echo ${X[2]}
echo ${X[3]}
echo ${X[4]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With