I've got a text file (clients) that contains around 150 lines of information
Each line is similar to :
"2","USERID","ACCESSCODE" Eg:
"1","545ghu","7687686686868709ioo98968g"
"1","G2567u","54564df76786470976476987w"
"1","Y5po97","iuioubhjgjg768b79j9890980"
I want to grep this file, only find entries containing G2 or Y5 in the second column, remove all Double quotes and send the result to an array.
I can do this with
foo=( $(grep 'G2\|Y5' clients | sed 's/"//g') )
This result in the array foo which contains entries like :
foo[0] = 1,G2567u,54564df76786470976476987w
What I'd like is the results in foo to look like this:
G2567u (54564df76786470976476987w)
Can someone advise how to do this ?
Thanks
(and)and missing first number. What are you doing to do with this array?arr=( $(...) )is an antipattern -- in general, you shouldn't ever do it. F/e, if one of the words emitted by your command substitution is*, you'll get a list of filenames in your array. Usereadarray,mapfile,read -a, or awhile readloop witharr+=( "$item" )instead.bash, instead of a language with a proper CSV library and real data structures.ID (Code)is neater to view and the '1' etc isn't needed.