Something not working quite right in arrays/parsing arrays..
Guys,
Here is what is not working is I am unable to parse the array :( Code:
N=0; Code:
+ N=0 Please assist here. Thank you. |
Your line
Code:
file_name=${input_file_array}|cut -d'/' -f7 You have here input_file_array and everywhere else input_files_array. You are piping to cut from a left hand side that produces no output. Maybe you meant Code:
file_name=$(echo ${input_file_array}|cut -d'/' -f7) |
2nd loop; see embedded comments
Code:
for i in "${input_files_array[@]}" You might also use arithmetic (( )) instead of 'let' http://wiki.bash-hackers.org/syntax/expansion/arith EDIT: use basename instead of cut |
Thank you for your improvement , works better but still not quite right. It just outputs same file name :(
|
Well I am curious about:
Code:
echo {file_name[$i]} |
@chrism01.
Many thanks for the assistance. It seems there is a problem with how we are defining a file name with cut command. Have a look at these ones. Code:
++ echo /data/integration/FIPaymentGateway/processDirectDebitDishonours/input/DDDHWBC0602012112012093600.TXT |
See my late EDIT: use basename cmd instead of cut; its what its designed to do.
|
Slowly and steady wins up the race.
Code:
for i in "${input_files_array[@]}"; do file_name=basename[$i]; echo ${file_name[$i]}; done |
doesn't work chrism01 :(
Code:
for i in "${input_files_array[@]}" Code:
basename: missing operand |
Guys,
Now I am becoming a little knowledgeable as to why are we using *two* loops when the job can be done within one loop itself ! ? |
What is the issue now?
Code:
N=0; Code:
+ let 'N= 165 + 1' |
You seem confused about when you've got an array & when you don't...
If you only want the bare filenames, stored in an array arr1 Code:
N=0; |
Yes chrism01 I am confused can you enlighten me please? I want to extract string(directory paths) and file names? What should I do. Please help me understand.
Thank you very much. |
Well, you can see how I got the filename using basename cmd; use dirname cmd to get the path if you want it as well.
You should bookmark and READ these http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ Use 'man cmdname' to lookup a cmd syntax or google it. |
I also like to use the parameter substitution method instead of basename:
Code:
file_name=${i##*/} |
All times are GMT -5. The time now is 10:52 AM. |