why this code is not working?
Code:
export input_config_file=/app/oracle/scripts/integration_file_monitoring/config/input_properties.file Code:
/data/integration/FIPaymentGateway/processBankCollectedTransactions/input=30 Code:
cat ${input_config_line}|while read line |
Just try:
Code:
#!/bin/bash |
@shivaa
Were you around when I was developing solution? :) I wrote exactly the same way you have given here and it did worked. I was however wonder if I do the same with for loop. It was good if yu can help me with clearing confusion of when to use ${}, $(). Adding confusion.. |
$( ) is command substitution. You use it whenever you want to capture standard output of a program.
Examples: Code:
current_directory="$( pwd )" Code:
for ((n=1; n<=10;n++)); do |
What doesn't work about your first script? I don't see anything obviously wrong with it, except that you're exporting "input_config_file" and then referencing "input_config_line".
|
Also the extra use of cut not required either, just set IFS for read to '=' and use to variables in read.
|
@grail.
Can you explain me a bit more on how not to use "cut" and use IFS? |
definitely it is working, otherwise you should report a bug, but bash is ok. Just it is not the program you need. Try to understand the code written and try to find out what will it really do and what do you really need.... Try to simplify your code and add comments about its functionality
instead of this: rec=$(echo $line|cut -d'=' -f1) rec2=$(echo $line|cut -d'=' -f2) rec=${line%%=*} rec2=${line#*=} would be better and quicker. You will not need { } in find as it was already mentioned and do not mix input_config_line and input_config_file. |
@pan64
May I please request to explain me the magic which you have written? |
@grail
Code:
while IFS=',' read line; do echo $1; echo $2; done<${input_config_file} Code:
/h1/h2/h3/h4/done,400,100,T meaning /h1/h2/h3/h4/done 400 100 T? Lot of manipulation can be done on that ! @pan64 Same question goes for you too. The technique which you have given, I could not understand , please tell me how can I extract individual strings as I asked above. Guys, This is now becoming very interesting ! Thank you all for your post! |
Well your second example would be more suited to an array, but if we look at the original question:
Code:
while IFS='=' read -r rec rec2 |
@grail
But if we want to read 3 string and don't want to read second string then in that case would it be not waste to read second string? Code:
while IFS='=' read -r rec rec2 rec3 |
@pan64
Would love to hear from you , about my questions ! Thanks in advance. |
I am not following your logic? You are reading a single line and it is being split into as many values as you like. being that the split is done a single time on the invocation of
read it would be using less memory than to read the single line and call external commands to perform your splitting as many times as you need. Your original solution requires you to call cut for each value you wish to receive. The current version requires the one read, which you are also still doing in your current scenario on top the cuts, and performs all splits as indicated by the number of variables (or an array) that you pass to read. |
Re ignoring certain fields, using IFS
Code:
input="a,b,c,d" |
All times are GMT -5. The time now is 03:03 AM. |