I have a few to questions pose in response first:-
Is this homework/assignment? There are specific forums for these.
What have you tried so far?
What output/errors do you get?
What OS and version are you using?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
We're all here to learn and getting the relevant information will help us all.
mm this is my personal script
i have create file with 1000 line with this format:
ip/port like 192.168.1.1/1055, let say ip.txt and create a core.sh file
main part of this project is when core.sh execute, it read ip and port from ip.txt and create 1000 files with this pattern:
can you explain what "NR" do ?
and how can i have this part IP[1], IP[1], IP[2] in loop?
i mean if ip file has 200 row, 200 file create and if it has 127 row, 127 file create, it depends on line number of ip file
In awk , NR is the "number of record", i.e. row or line No. Above small script will loop through your input file, creating n files for n lines in file, i.e. FILE1, FILE2, ... FILEn. Did you check? Please consider Don Cragun's hint if your line count exceeds the system parameter OPEN_MAX ( getconf OPEN_MAX ):
I agree with RudiC that you would find life much easier working problems like this if you take a little time to learn how to use awk . You might also try the following which doesn't need either invocation of cat and just uses shell built-ins:
NR=0
while IFS=/ read -r ip port
do NR=$((NR + 1))
printf 'internal=yes\ninternalip= %s\ninternal.dest: %s port=%s\n' \
"$ip" "$ip" "$port" > FILE$NR
done < ip.txt
which produces output filenames like FILE1 , FILE2 , ... FILE1234 , etc., or if you would prefer output filenames like FILE0001 , FILE0002 , ... FILE1234 , etc. you could try:
NR=0
while IFS=/ read -r ip port
do NR=$((NR + 1))
FILENAME=$(printf 'FILE%04d' $NR)
printf 'internal=yes\ninternalip= %s\ninternal.dest: %s port=%s\n' \
"$ip" "$ip" "$port" > "$FILENAME"
done < ip.txt
Either of these should work with any shell that attempts to follow the POSIX standard's shell syntax (such as bash , ksh , and several others; but not csh and its derivatives).