1

I am having a problem, I am sure it is something very simple that I am over looking but, I can not seem to see it.

So I am trying to loop through an Array, Do some with using the content of each element and then using the element as a file to redirect too.

fullProc=$(grep "WNDP_Server" $1 | grep -v "#" | cut -f 2  | grep -v /nwsys/release/conf/save" | cut -d '/' -f5)
for i in "${fullProc[@]}"
do
   echo "$host$HostName" > "$i"
   grep "WNDP_Server: * " $1 | grep -v "#" | cut -f 2-3 | grep -v "/nwsys/release/conf/save" | grep -w "$i" | cut -f 2 >> "$i"
   grep "WNDP_Port:" $1 | grep -v "#" | grep -w "$i" | cut -f 3 >> "$i"
   ProcName=$(grep "WNDP_Server: * " $1 | grep -v "#" | cut -f 2  | grep -v "/nwsys/release/conf/save" | cut -d '/' -f5 | grep -w "$i" | cut -d '.' -f1)
   echo "Process: $ProcName" >> "$i"
   grep -w "FilterMode:" $1 | grep -v "#" | cut -f 2-3 | grep -w "$i" | cut -f2 >> "$i"
   grep -w "Filter:" $1 | grep -v "#" | cut -f 2-3 | grep -w "$i" | cut -f2 >> "$i"
done

What I get is a single file with all the correct information. instead of multiple files each with their corresponding information.

If you need me to clarify this please let me know.

$i is the file name in question.

4
  • 1
    Show you sample input and output. Commented Jan 8, 2014 at 20:13
  • 1
    What are the multiple files you want to get? Commented Jan 8, 2014 at 20:14
  • For example $fullProc=( xprofd.cfg , xprofd.cfg2 ). So i am trying to fill xprofd.cfg with certain information, and loop to xprofd.cfg2 and fill it with its own information Commented Jan 8, 2014 at 20:17
  • Please include the code in your post that sets the value of fullProc Commented Jan 8, 2014 at 20:27

1 Answer 1

1

You should assign fullProc like this:

fullProc=($(grep ...))

Notice the extra (...) around the $(grep ...).

Otherwise all the matches of grep will be in a single string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.