Reset different and multiple .txt file content to 0


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reset different and multiple .txt file content to 0
# 1  
Old 07-04-2012
Reset different and multiple .txt file content to 0

I need help. I have to create a cron job that will reset the value of different and multiple .txt file to 0.

Example:

Actual
Code:
172_21.txt = 25
192_101.txt = 10
192_168.txt = 5
10_10.txt = 3

After the cron job
Code:
172_21.txt = 0
192_101.txt = 0
192_168.txt = 0
10_10.txt = 0

The cron job will be run every 12:00 Mid Night.

Thanks for the help.

Last edited by Franklin52; 07-05-2012 at 08:29 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-04-2012
If all lines of text are exactly xxx = xxx, i.e. two spaces and three set of characters:
Code:
for file in file1.txt file2.txt lastfile.txt
do
    awk '{ print $1, $2, "0" }' $file > tmp.tmp
    mv tmp.tmp $file
done

# 3  
Old 07-04-2012
Quote:
Originally Posted by jim mcnamara
If all lines of text are exactly xxx = xxx, i.e. two spaces and three set of characters:
Code:
for file in file1.txt file2.txt lastfile.txt
do
    awk '{ print $1, $2, "0" }' $file > tmp.tmp
    mv tmp.tmp $file
done

Thanks jim for the response. I tried the command you gave but it only append the 0 to the xxx. It doesn't overwrite the xxx with 0.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. Shell Programming and Scripting

To substitute multiple variable by their content in a file

Dear All, I would like to instantiate a "pattern file" substituting "variable name" by their content. Saying, we have: 1/ a "pattern file" containing different "variable name", the first character of the "variable name" is "@": $ cat TPTModl.txt DEFINE... (12 Replies)
Discussion started by: dae
12 Replies

3. Shell Programming and Scripting

How to replace multiple file content?

Hi Gurus, I need replace multiple files content. the file name pattern likes currentfile_code_* the content pattern in the file like text=value I need replace the content as text=abcde Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

4. UNIX for Dummies Questions & Answers

redirecting arguments in a script to multiple lines in a .txt file

Ok hope my vocab is right here, i'm trying to write multiple sets of arguments to another file for example: I have a script that accepts four arguments and sends them to a another file $write.sh it then out in so the file receiver.txt would contain this: it then out in what... (2 Replies)
Discussion started by: austing5
2 Replies

5. UNIX for Dummies Questions & Answers

Help with Aligning the content of a txt file

Hello friends Please help me to display the content of a file in specific aligned manner. for ex. the content of the file may be >$TEST WELCOME HI HELLO UNIX SHELL SCRIPTING >$ I want to display the content like . TEST WELCOME HI HELLO ... (18 Replies)
Discussion started by: rajmohan146
18 Replies

6. UNIX for Dummies Questions & Answers

sed insert content of file.txt to multi files

Ive this sed & find command find /home/www/ -name footer.php -exec sed -i 's/<\/body>/file.txt\n<\/body>/' what I need to place content of file.txt before </body> in all footer.php files file.txt content is google analytic script which is like 7 lines any help to adjust my command to... (2 Replies)
Discussion started by: xmoe
2 Replies

7. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

8. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies

9. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies

10. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies
Login or Register to Ask a Question