![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error file Redirection | maxmave | Shell Programming and Scripting | 3 | 04-23-2008 09:17 AM |
| awk two file redirection | kamel.seg | Shell Programming and Scripting | 1 | 12-18-2007 10:17 AM |
| Unix command redirection | swap007 | Filesystems, Disks and Memory | 1 | 10-06-2007 04:52 AM |
| .forward file for mail redirection | giannicello | UNIX for Dummies Questions & Answers | 3 | 01-12-2002 07:06 AM |
| File redirection | namtab | UNIX for Dummies Questions & Answers | 4 | 01-10-2002 07:48 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
echo command and file I/O Redirection
I have a colon-delimited text file of names, addresses and phone numbers. I am trying to write a script that can add additional entries and then sort it alphabetical by last name and resave it to the original file. I am using C shell to script. This is the section of my script that I wish to sort the data file and then save it to itself:
Code:
set file = `sort -k1,2 $myfile` echo $file > $myfile Code:
sort -k1,2 $myfile > 0 cat 0 > $myfile rm 0 My underlining question is: How can I sort the data file and then save it back into itself without having to create a temporary file '0' and still have the newline characters that separate each row remain? Thanks Last edited by userix; 05-09-2008 at 09:43 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
even sort uses temp files check out the option -T Code:
-T, --temporary-directory=DIR
use DIR for temporaries, not $TMPDIR or /tmp; multiple options
specify multiple directories
|
|
|||
|
I am curious if it is possible to do it without temp file, because I can set the data into a variable, but the only problem is the newlines not being stored as well. Is this a limitation with the 'set' command, or the 'echo' command. This a CS class project I have to complete. So in the end, I have to give read and execute permissions to my professor. If I give him r+x permissions and he runs the script from my personal folder, would it not be able to create a temp file, since he does not have write permissions in my folder?
|
|
|||
|
Quote:
If I need to allow him to run my script from within my directory, would giving him read, write, and executable allow the temp file to be created and deleted when he runs the script? I want to make sure my script runs exactly as I intend it to and not glitch up because the temp file cannot be created when it comes to the point in my script where I resave the sorted data. That is why I asked the question in OP. If I can temporarily store the data correctly in a variable and then re-set it to the original file, I wouldn't have to worry about using a temp file. Thanks for your replies. |