Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
A)
Input
================
testAAAA svc stream
#rexd sunrpc_tcp
#rstatd sunrpc_udp

batch file
================================================
copy D:\11\Input tmp0.txt

sed "/#/d" tmp0.txt > Output.txt

copy Output.txt D:\11

del tmp*.txt

Output
================
testAAAA svc stream :)


B) I add in ##infront of the testAAAA and add in echo No configuration found > Output.txt in the batch file.

Input
================
##testAAAA svc stream
#rexd sunrpc_tcp
#rstatd sunrpc_udp

batch file
================================================
copy D:\11\Input tmp0.txt

sed "/#/d" tmp0.txt > Output.txt

copy output.txt D:\11

echo No configuration found > Output.txt

del tmp*.txt

Output
================
No configuration found :)

But When i use the batch file from B and delete away the ##infront of testAAAA the output i get is No configuration found instead of testAAAA svc stream :(

How should i program it in order to suit both A and B :confused:

The result i want is when the input is all in ## my output is No configuration found. When there is a line in input that do not have # , my output will display the line. :(
 

satyam90

macrumors regular
Jul 30, 2007
242
0
Bangalore, India
Am I right if I say that the result u are expecting is :
1. When a line starts with ## it should not be deleted.
2. When a line starts with # it should be deleted.
3. When a line don't start with ## it should not be deleted.

Right?
 

aross99

macrumors 68000
Dec 17, 2006
1,541
1
East Lansing, MI
You will always get "No Configuration Found", because you don't have any type of conditional statement controlling that statement.

Your Shell will do the Copy, the Sed, the 2nd Copy, and then echo "No configuration found" - every time.

When so you want to see this message? Maybe when there are no lines left?
 

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
Am I right if I say that the result u are expecting is :
1. When a line starts with ## it should not be deleted.
2. When a line starts with # it should be deleted.
3. When a line don't start with ## it should not be deleted.

Right?

1. when a line starts with ## or # it should be deleted and display no configuration found
2. when a line don't start with ## or # it should not be deleted and it will display the line.
 

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
You will always get "No Configuration Found", because you don't have any type of conditional statement controlling that statement.

Your Shell will do the Copy, the Sed, the 2nd Copy, and then echo "No configuration found" - every time.

When so you want to see this message? Maybe when there are no lines left?

when there are lines it will display the lines but when there are no lines it will display no configuration found.
 

satyam90

macrumors regular
Jul 30, 2007
242
0
Bangalore, India
If script can be ok for you, see the following code:

Code:
sed "/^#/d" test.txt > out.txt 
if [[ `ls -lrt out.txt | awk '{print $5}'` = 0 ]] 
then 
        echo "No Configuration found" > out.txt 
fi
Place it in a file, save it, change mode and run it.
 

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
If script can be ok for you, see the following code:

Code:
sed "/^#/d" test.txt > out.txt 
if [[ `ls -lrt out.txt | awk '{print $5}'` = 0 ]] 
then 
        echo "No Configuration found" > out.txt 
fi
Place it in a file, save it, change mode and run it.

batch file

copy D:Input tmp0.txt

sed "/^#/d" tmp0.txt > out.txt

if [[ `ls -lrt out.txt | awk '{print $5}'` = 0 ]]

then
echo "No Configuration found" > out.txt
fi

copy out.txt D:\out

del tmp*.txt

hmm after i run the script it display `ls was unexpected at this time.

It output 2 file in d: -> out.txt and tmp0.txt
when there are lines in the input file, out.txt display the lines while tmp0 display the original input file.
when all lines are in ## in input file, out.txt is blank and tmp0 display the orginal input file.
 

satyam90

macrumors regular
Jul 30, 2007
242
0
Bangalore, India
I thought u might be running the script in Linux/Unix or Mac environment and the script is according to that. But I think u are running in Windows environment. "ls" command must be replaced accordingly in Windows. I will try out and let you know if I succeed.
 

rita1985

macrumors newbie
Original poster
Dec 25, 2007
13
0
I thought u might be running the script in Linux/Unix or Mac environment and the script is according to that. But I think u are running in Windows environment. "ls" command must be replaced accordingly in Windows. I will try out and let you know if I succeed.

Thanks for ur help i have solve the problem (^-^)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.