Or, more simply:
The sort utility is one of the very few standard utilities that provides an option to non-destructively overwrite one of its input files.
But, I have no idea how you got two lines in your sorted output that contained b when that text only appeared on one line in your input file???
Hi Dave,
1. I don't want to create another file, i just want to sort the contents of the Test file itself.
Thanks for your help.
Hi Don,
But, I have no idea how you got two lines in your sorted output that contained b when that text only appeared on one line in your input file???
>> Actually the files has content of alphabets from a-z. In order to shorten the text i edited the output and input.
Between, this command erased the contents of my file.
Regards,
Chandu
Last edited by rbatte1; 09-23-2014 at 07:30 AM..
Reason: Added CODE tags
This is a common problem. When you run the command, the output file is opened (and overwritten) before you start to read the input, which by now is null. You command then exists as it finishes reading no input.
You will need to read the input and write to a separate output file. If need be, then rename (and overwrite) the input file thus:-
It does mean that you have to consider space for having the two files at the same time, even if just for a moment.
Hi Dave,
1. I don't want to create another file, i just want to sort the contents of the Test file itself.
Thanks for your help.
Hi Don,
... ... ...
Between, this command erased the contents of my file.
Regards,
Chandu
You did not show us what was in the file Test before the sort. I suggested using:
which will require temp file space to sort the input file, but overwrite the input file if the sort succeeds. If there isn't enough space, sort will fail but the original data in the input file will not be disturbed. (However, if there is enough space to sort the input file into another file and some other process is filling up the filesystem while sort is trying to overwrite the input file with the sorted results, there is no guarantee that data won't be lost.)
Using the command you used:
tells sort to sort the contents of the file Test into a temp file and if the sort completes successfully, overwrite the contents of the file Tested with the sorted results. In any case, the original contents of Test will be unchanged. So, since Test was an empty file, Tester was successfully overwritten by the sorted contents of the empty file Test.
I have a script that sorts and processes unsorted files to newly created directories.
Its working great, but I am trying to understand the leanest method to get the script to create an additional file within each newly created directory that:
Contains a list of all files in the directory... (4 Replies)
Hi,
Right now there is a file called 'qm.ini' which is owned by mqm:mqm and I am trying to replace a line from this file with something else and save.
I am using the below perl command to replace and save within a shell script with a different user called 'mqadm' which is also part of mqm... (1 Reply)
Hi Team,
Not getting the file output inside my email which i am sending from unix box. . Please refer the below code :
#!/bin/sh
{
sleep 5
echo ehlo 10.56.185.13
sleep 3
echo mail from: oraairtel@CNDBMUREAPZP02.localdomain
sleep 3
echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Hello,
I'm using Windows 7 ; sed, awk and gnuwin32 are installed.
I have a big text file I need to manipulate.
In short, I will have to split it in thousands of short files, then rename and save in a folder which name is based upon filename.
Here is a snippet of my big input.txt file (this... (4 Replies)
I need that a certain part of the content below excluded
==Image Gallery== followed by <gallery> and the content until </gallery>
test SED1
==Image Gallery==
<gallery>
Image:car1.jpg| Car 1<sup>1</sup>
Imagem: car2.jpg| Car2<sup>2</sup>
</gallery> test SED2
==Image... (5 Replies)
I have the file sed1.txt and I need to strip the brackets (]) and content inside them only when
I have two or three letters followed by a colon.
for example,it may be any letter, not just abc
]
]
#-- cat sed1.txt
1 ] FISICA
2 ]PORTUGUES
3 ] ]MATEMATICA
4 ]]INGLES ]
5 ]QUIMICA
6... (2 Replies)
I'm using the following script to check cisco router health and I'd like to save output to a file,
vty_runcmd.sh > /check/check-cisco-health
script works and output is saved to a file. However using it in crontab file is created but output is not printed inside it. In crontab,
*/5 * * * *... (4 Replies)
Hi,
How to add string inside the file. In this case adding 63 in the beginning of each line. Thnks.
e.g. what is inside the file
Mobile Number Portability
9051151234
9051261345
9051393245
9051412345
9051507654
should like this as output:
Mobile Number Portability (7 Replies)
Hi,
What are the contents of /var/sadm/pkg/<pkg>/save directory.
- It contains various patches with their id's.
What does the "pspool" directory inside it contain? (6 Replies)