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:
This code works and does sort, but the problem comes when I try to echo the sorted data back into the original file. Echo apparently does not show the original newline characters, so the updated file I get no longer is sorted by rows, but rather one continuous string. Or the problem could lie in the setting of the 'file' variable, in which newline characters are not set into the variable 'file' as well. I have tried another method using the following code:
Basically above, instead of using the echo command, I actually redirect the sorted output to a temporary file called '0' and then cat it back, overwriting the original contents of $myfile. While this method works, it requires that I temporarily create the '0' file.
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
Hi
I am using nohup command in script(say nohup ls- ltr > somefile 2>&1 & ). I dont want any kind of output to be displayed on screen. When i tried the above nohup it still gives me some out put on screen like
2991
Done >somefile 2>&1
Please you let me know what is... (3 Replies)
Hi,
When I run the following command in terminal it works. The string TEST is appended to a file silently.
echo TEST | tee -a file.txt &>/dev/null
However, when I paste this same line to a file, say shell1.sh, and use bourne shell .
I run this file in terminal, ./shell1.sh.
However I... (1 Reply)
I am using tar command to append daily database backups on tape. "tar --append " command help me to do this.
But tar --append command does not produce any output on stdout if it succeed.
I want the output for that appended command to a log file.
This log file should contain only the name of the... (0 Replies)
Hi All,
I want to display content on command promt and also write in file.
For that iI ahve to write two sentence
echo "XXXXXXX"
echo "XXXXXXXX" >> 1.txt
Is there any way to write in one echo statement (1 Reply)
I am trying to write a simple script which prints some output, but also saves the same in a logfile.
echo hello
echo hello >> logfile
Is there anyway i Can write single sentence of code and get the same result:
( i am using CSH ) (4 Replies)
Dear All,
./waf --run scratch/myfirst > log.out 2>&1
The above is a command line to redirect the output to a file called log.out.
what is the 2>&1 part for ?
Thank you (2 Replies)
Hello,
I'm new to Unix (working with OS X 10.8.5) and therefore at the beginning of my adventure. If I ask something stupid, then this is not intentional, but simple nescience. :rolleyes:
I have a problem with the redirection of text file content to echo. I was experimenting with redirection... (6 Replies)
Hi,
I have a peculiar issue w.r.t redirecting the command output to a file when using loop.
I am redirecting command output to same file in a series of if condition statements, but if one block of if condition statement writes the log to the file , the subsequent block of if condition... (7 Replies)
Discussion started by: ananan
7 Replies
LEARN ABOUT SUSE
libtmpfile
Netpbm subroutine library: pm_tmpfile() function(3) Library Functions Manual Netpbm subroutine library: pm_tmpfile() function(3)NAME
pm_tmpfile() - create a temporary unnamed file
SYNOPSIS
#include <netpbm/pm.h>
FILE *
pm_tmpfile(void);
EXAMPLE
This simple example creates a temporary file, writes 'hello world' to it, then reads back and prints those contents.
#include <netpbm/pm.h>
FILE * myfileP;
myfile = pm_tmpfile();
fprintf(myfile, 'hello world0);
fseek(myfileP, 0, SEEK_SET);
fread(buffer, sizeof(buffer), 1, myfileP);
fprintf(STDOUT, 'temp file contains '%s'0, buffer);
fclose(myfileP);
DESCRIPTION
This library function is part of Netpbm(1)
pm_tmpfile() creates and opens an unnamed temporary file. It is basically the same thing as the standard C library tmpfile() function,
except that it uses the TMPFILE environment variable to decide where to create the temporary file. If TMPFILE is not set or is set to
something unusable (e.g. too long), pm_tmpfile() falls back to the value of the standard C library symbol P_tmpdir, just like tmpfile().
Unlike tmpfile(), pm_tmpfile() never returns NULL. If it fails, it issues a message to Standard Error and aborts the program, like most
libnetpbm routines do.
If you need to refer to the temporary file by name, use pm_make_tmpfile() instead.
HISTORY
pm_tmpfile() was introduced in Netpbm 10.20 (January 2004).
netpbm documentation 22 July 2004 Netpbm subroutine library: pm_tmpfile() function(3)