Delete file content by asking user Yes/No...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete file content by asking user Yes/No...
# 1  
Old 03-30-2015
Delete file content by asking user Yes/No...

I have following script to ping multiple ips but i want to delete ip.csv file content after running script .....but before deleting content i have ask user yes/No prompt depend on user input Yes/no ip.csv content will delete..


Code:
#!/bin/bash

for enodeb in `cat /tmp/ip.csv`
do
ping -c 2 $enodeb 1> /dev/null
if [ $? -eq 0 ]
then
echo -e "$enodeb     PASS" >> /tmp/list.csv
else
echo -e "$enodeb     FAILED" >> /tmp/list.csv
fi
      done
cat /tmp/list.csv


i use this it work but giving me error on "$ >ip.csv ;" line...
Code:
read -p "You want to clear ip.csv file ip's press(y/n)?" CONT
if [ "$CONT" == "y" ]; then
       $ >ip.csv ;  #giving eror on this line
  echo " ip.csv file is empty now ";
else
  echo "OK bye";
fi


PLease help me......

Last edited by vgersh99; 03-30-2015 at 11:36 AM.. Reason: code tags: icode != code
# 2  
Old 03-30-2015
The $ is not a command Smilie

Change it to:
Code:
echo "" > ip.csv

hth
This User Gave Thanks to sea For This Post:
# 3  
Old 03-30-2015
Thanks...
# 4  
Old 03-30-2015
> ip.csv would suffice, I think. This would not delete the file but render it empty.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

2. UNIX for Dummies Questions & Answers

How to create a file even root user also cant delete?

Is there any way to create a file in linux that root user also can't delete? (8 Replies)
Discussion started by: palani13dec
8 Replies

3. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

4. Shell Programming and Scripting

want to search some content of the file with specific to user

I have some users in one unix system and i want to search some files with specific to user and then i want to find some content inside that file so can u help me how we can implement it? File location is as below. /pools/home_unix/cmadireddy/work/models/model/ cmadireddy is user name. now... (6 Replies)
Discussion started by: lathigara
6 Replies

5. Shell Programming and Scripting

how to delete special characters from the file content

Hello Team, Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content. ---------------------------------------- Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
Discussion started by: kanakaraju
2 Replies

6. Shell Programming and Scripting

Delete content of file 1 in file 2 with shell script

OK, best is I explain what the operating enviroment is. Linux, but Motomagx. It is a Linux operated mobile phone, Motorola V8. I am writting a shell script, but got stuck. I have to delete the complete content of file 1 in file 2. I have attached the 2 files. You can see that the content of... (2 Replies)
Discussion started by: rasputin007
2 Replies

7. Shell Programming and Scripting

how to delete content in a file (delete content only)

Hi Friends I have a file called processLog.txt file processLog.txt --------------- echo "line starts "$LINE suppCode=${LINE:0:3} #gatewayArchive=`scp root@mrp-gateway:/usr/local/apache/data/PLAT/MIMUS/upload/PROD/archive/112042708173000.txt /home/krishnaveni/scripts/tempFolder` #echo... (5 Replies)
Discussion started by: kittusri9
5 Replies

8. UNIX for Advanced & Expert Users

Delete user file(s) older then 'X' days ??

I want to delete any file in unix file system which is older then a week. Those files should not be unix system file..means it should be user created file. Any clue to this ?? ASAP. Thanks. (2 Replies)
Discussion started by: varungupta
2 Replies

9. UNIX for Dummies Questions & Answers

To delete content of many file

Hi All, I want to delete the content of some files,which are specified through wild-card option,but i want to restore the file. I.e I just want to delete the contents file parameters shouldn't be changed. . Please provide me the answer. Thaning u all in advance Athresh (4 Replies)
Discussion started by: athresh
4 Replies
Login or Register to Ask a Question