Sponsored Content
Full Discussion: overwriting on a file
Special Forums UNIX Desktop Questions & Answers overwriting on a file Post 302700067 by Don Cragun on Thursday 13th of September 2012 01:13:55 AM
Old 09-13-2012
Any time you have a pipeline that reads from a file that is overwritten by a redirection at the end of the pipeline, you will lose data. The shell's will wipe out the current data in the file specified by the redirection before any command in the pipeline has a chance to read from it.

However, you could add:
Code:
        mv F2/$name /F1

after the pipeline starting with sort in your for loop as long as:
  1. There are no spaces, tabs, newlines, or other special characters in any of your filenames,
  2. there are no hard links to any of the file in directory F1, and
  3. you have sufficient space available on the file system.
If 1 or 3 above is not true, your script already has problems. If there are hard links to files in F1 that you need to preserve, your could replace the command added above with:
Code:
        cp F2/$name F1/$name && rm F2/$name

to preserve the links.

You could also simplify the and speed up your script if you replace:
Code:
sort  $X | uniq  | awk '{ $1=""}1' | awk '{ $NF=""}1'  > F2/${name}

in your loop with:
Code:
sort -u $X | awk '{ $NF="";$1=""}1' > F2/${name}

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Does "gzip" have a no prompt option on it for overwriting if file exists?

So I dont enounter things like: gzip: /sometimename.gz already exists; do you wish to overwrite (y or n)? Want to add it into a script and if there is a file aready there to just overwrite it, otherwise the script will hang unless there is manual intervention. (1 Reply)
Discussion started by: LordJezo
1 Replies

2. Shell Programming and Scripting

successive file renaming & overwriting

Hi all, In our webserver customer wants to see the latest 10 files arrived. So the names are hardcoded in webpage like : filename_01.txt filename_02.txt .... .... filename_10.txt where the filename_01.txt is the latest one (typically the output of ls -1t) in the /../webpage directory.... (2 Replies)
Discussion started by: sabyasm
2 Replies

3. Shell Programming and Scripting

Overwriting File

How to overwrite every time a particular portion of a file? ---------- Post updated at 02:16 PM ---------- Previous update was at 02:07 PM ---------- I have a file whose contents are something like: Output of "apachectl fullstatus" command: ---------------------------------------------... (3 Replies)
Discussion started by: proactiveaditya
3 Replies

4. Programming

Copying and overwriting a file using file descriptor

Hi , i have two basic requirement on linux platform . I am using C language to do this . 1) copying one file to another (assuming i know their file descriptors) 2) Overwriting a file using it file descriptor . Please guide. regards Aki (2 Replies)
Discussion started by: meet123321
2 Replies

5. Linux

Is it possible to revert a file after overwriting it ?

Long story short, there was some sort of corruption with my ide and the script I was working on has been over written with nothing (the file is blank now). The IDE doesn't store a back up from what I know (I'm using notepadd++ in wine lol I know I know I'm addictted to the nppftp sidebar and geany... (1 Reply)
Discussion started by: noPermissions
1 Replies

6. Shell Programming and Scripting

Overwriting file with sftp

I have a script, which runs through cronjob every night 9 PM. It is supposed to do following tasks -- 1- Connect to ftp.testsite.com via user redtest 2- Fetch file red_bill.txt to my local server, where my script is residing. 3- Rename red_bill.txt to red_bill.V01.txt everyday on sftp server.... (4 Replies)
Discussion started by: solaris_1977
4 Replies

7. Shell Programming and Scripting

File overwriting

Hi, An application is transferring a file to linux system with same file name. As file is transferring with same name always file will be overwritten. In this case we want to know what times file was overwirtten like below. Modify: 2014-05-12 00:52:01.000000000 Modify: 2014-05-12... (2 Replies)
Discussion started by: Satyak
2 Replies

8. Shell Programming and Scripting

sed is not overwriting a file

hi i have a file as in follwoing: cat apple.txt Apple is a fruit But this fruit is costly Now I used the sed command and i see output as in following # sed 's/fruit/healthy &/' fruit.txt Apple is a healthy fruit But this healthy fruit is costly # sed works fine here. But... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

9. Shell Programming and Scripting

Avoid overwriting backup file when multiple entries need to replace in one file input from another

Hello, I have been working on script in which search and replace the multiple pattern. 1. update_params.sh read the multiple pattern from input file ParamMapping.txt(old_entry|New_entry) and passing this values one by one to change_text.sh 2. change_text.sh read... (0 Replies)
Discussion started by: ketanraut
0 Replies

10. UNIX and Linux Applications

Logrotate with catalina.out "daily compressed file is overwriting the logs"

Hi Everyone, We are trying to do a logrotate for "catalina.out" daily, So have used the "copytruncate" option in the logrotate configuration but ended up seeing there was a 0kb file touched with "catalina.out" and the other file with the current date(compressed) file created and seems the log is... (2 Replies)
Discussion started by: thiyagoo
2 Replies
tracker-miner-fs(1)						   User Commands					       tracker-miner-fs(1)

NAME
tracker-miner-fs - Used to crawl the file system to mine data. SYNOPSIS
tracker-miner-fs [OPTION...] DESCRIPTION
tracker-miner-fs is not supposed to be run by the user since it is started by its .desktop file when the user logs in. It can also be started manually of course for debugging purposes. You can not run more than one instance of this at the same time. tracker-miner-fs mines information about applications and files only. OPTIONS
-?, --help Show summary of options. -V, --version Returns the version of this binary. -v, --verbosity={0|1|2|3} Sets the logging level, 0=errors, 1=minimal, 2=detailed, 3=debug. -s, --initial-sleep=SECONDS Sets the initial sleep time before crawling the file system is started. If the --no-daemon option is used, this option is ignored. -n, --no-daemon Tells the miner to exit once all indexing has finished and the database is up to date. This is not the default mode of operation for the miner, usually it stays around acting like a daemon to monitor file updates which may occur over time. This option renders the --initial-sleep option moot. -e, --eligible=FILE Checks if FILE is eligible for being mined based on the current configuration rules. In addition to this, it will check if FILE would be monitored for changes. This works with non-existing FILE arguments as well as existing FILE arguments. -d, --disable-miner=MINER Tells the daemon to disable the in-house miners it supports. Depending on build options, this can be 'Files', 'Applications' and 'Userguides'. This option can be provided more than once to diasable multiple miners. Disable in this case means the miner is not started, though all miners still register themselves on D-Bus and appear there, no actual action is performed otherwise (such as crawling, setting up monitors, or checking mtimes against the file system). ENVIRONMENT
TRACKER_USE_LOG_FILES Don't just log to stdout and stderr, but to log files too which are kept in $HOME/.local/share/tracker/. This came into effect in 0.15.3 and 0.16.0. After this version of Tracker, logging to file (usually useful for debugging) can only be done by declaring this environment variable. TRACKER_USE_CONFIG_FILES Don't use GSettings, instead use a config file similar to how settings were saved in 0.10.x. That is, a file which is much like an .ini file. These are saved to $HOME/.config/tracker/ SEE ALSO
tracker-store(1), tracker-info(1). GNU
September 2009 tracker-miner-fs(1)
All times are GMT -4. The time now is 08:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy