Defining loop statement for creating new file each time
Hi, I am scripting new bee here please can anyone guide me i want to create a simple script which will redirect data from input file and while redirecting will check for output file if exist then will create new like if test1 there then test2 ..test3 so on...
here is my script i dont know how feasible it is.. #!/bin/bash echo "Enter the file to be used: \c" read flname echo "searching for file $flname" grep "$pname" $flname echo "Selected records name shown above" if [ ! -f $flname ]; then echo "File $flname does not exists! Please provide the exact path" else echo "File exist using input from $flname" fi if [ -e $flname ]; then echo "Enter first line number to start input data" read n echo "Enter last line number to input data" read m else "Provide exact number of lines" fi test=${n}test if [ -e $nline ]; then cut -c $n-$m $flname > $test else echo "can'not input data please put right info" fi if [ -e $test ]; then echo "File $test exist creating new `touch ${n}test`" else echo "File does not exists" fi I want here some statement which will loop and create new file..each time |
It is not really clear what you're trying to do. Can you post an example of input file and what an output file should be based on the user's input? Anyway, here is some correction to your script:
Code:
#!/bin/bash |
No need for loops if we limit to test9
$ num=$( ls test? | tail -1 | sed 's/test//' ) $ num=$(( num+1 )) The file name is $ test=test"$num" |
Quote:
|
Quote:
|
Quote:
#!/bin/bash echo "Enter the file to be used: \c" read flname if [ ! -f $flname ]; then echo "File $flname does not exists! Please provide the exact path" exit else echo "File exist using input from $flname" fi if [ -e $flname ]; then read -p "Enter first line number to start input data: " n read -p "Enter last line number to input data: " m else "Provide exact number of lines" fi num=1 while [ -e test$num ]; do num=`expr $num + 1` echo test_${num:1} done cut -c $n-$m $flname > test$num if [ -e test$num ]; then echo "File $test exist creating new test$num" else echo "File does not exists" fi just please guide me for appending date format...i dont want to use mv or paste..if file exist with date format then it should create new with %y%m%d-1 or %y%m%d-2 ....-3, -4 so on. |
Quote:
#!/bin/bash echo "Enter the file to be used: \c" read flname if [ ! -f $flname ]; then echo "File $flname does not exists! Please provide the exact path" exit else echo "File exist using input from $flname" fi if [ -e $flname ]; then read -p "Enter first line number to start input data: " n read -p "Enter last line number to input data: " m else "Provide exact number of lines" fi num=100 d=`date +%y-%m-%d` while [ -e logfile.log-$d-$num ]; do num=`expr $num + 1` echo logfile.log-$d-${num:1} done cut -c $n-$m $flname > logfile.log-$d-$num if [ -e logfile.log-$d-$num ]; then echo "file exist created new" else echo "File does not exists" fi Thank you so much to both of you for helping me... |
All times are GMT -5. The time now is 07:17 AM. |