Sponsored Content
Full Discussion: append character to a file
Top Forums Programming append character to a file Post 302120973 by porter on Monday 11th of June 2007 04:22:49 AM
Old 06-11-2007
either

Code:
FILE *fp=fopen(filename,"a");
fputc('q',fp);
fclose(fp);

or

Code:
int fd=open(filename,O_WRONLY);
char buf[1];
buf[0]='q';
lseek(fd,0L,SEEK_END);
write(fd,buf,1);
close(fd);

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using SED to append character to each line

Hey - my first post here, and I'm a total SED newb. I've looked around for previous help on this, but have so far been unsuccessful. I have a program (AMStracker for OS X) that outputs data in the terminal. Output is in this form: . . . 3 0 -75 3 0 -76 3 0 -77 ... (4 Replies)
Discussion started by: c0nn0r
4 Replies

2. UNIX for Dummies Questions & Answers

How to Replace,Sort,and Append Character one script

Hi all i am very new to shell scripting,hope u guys can help i need to replace,sort and append character for the file that look like this: 1007032811010001000100000001X700026930409 1007032811010001000200000002X700026930409 1007032711020001000300000003X700026930409... (2 Replies)
Discussion started by: ashikin_8119
2 Replies

3. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies

4. Shell Programming and Scripting

Sed append newline character

Hi All, I am new to Shell scripting.. I have a task to parse the text file into csv format. more then half the things has done. But the problem is when I use the sed command in shell script. it appends newline character at the end of the line. and so when I open the file in CSV it's format... (3 Replies)
Discussion started by: Gaurang033
3 Replies

5. Shell Programming and Scripting

How do I append a ^M to the end of each 129 character string

Hello all, I have a stumper of a problem. I am trying to append a ^M or "newline" to the end of each 129 character string in a huge file in unix. Each string starts with A00. I am trying to get the file to go from... A00vswjdv1 Test Junk Junk A00vswjdv2 Test Junk Junk ... (6 Replies)
Discussion started by: Captain
6 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

7. Shell Programming and Scripting

Find string in a file and append character

Hi Experts, Is there a way to find a string in a file then append a character to that string then save the file or save to another file. Here is an example. >cat test.txt NULL NULL NULL 9,800.00 NULL 1,234,567.01 I want to find all NON NULL String and add a dollar sign to those... (9 Replies)
Discussion started by: brichigo
9 Replies

8. Shell Programming and Scripting

To append Character in file

hi, i am having a file which is comma seperated , i need to append a char in particular column for eg: infile aa,bb,c,dd,ee zz,yy,sss,ddd,ff . . i need to append for eg 4th column with a char like 'LQ' output: aa,bb,c,LQdd,ee zz,yy,sss,LQddd,ff (12 Replies)
Discussion started by: rohit_shinez
12 Replies

9. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies

10. Shell Programming and Scripting

Adding character and append last element of second column

Hi, could you help me in processing this file under bash? I need to add some text to the first line and then append the last element of the second columns. The input file is tab separated while the output should be space separated. input file is 1.00E-02 2.00E-02 4.465E+17 2.00E-02 3.00E-02... (4 Replies)
Discussion started by: f_o_555
4 Replies
fopen(3s)																 fopen(3s)

Name
       fopen, freopen, fdopen - open a stream

Syntax
       #include <stdio.h>

       FILE *fopen (filename, type)
       char *filename, *type;

       FILE *freopen (filename, type, stream)
       char *filename, *type;
       FILE *stream;

       FILE *fdopen (fildes, type)
       int fildes;
       char *type;

Description
       The  routine opens the file named by filename and associates a stream with it.  The routine returns a pointer to the FILE structure associ-
       ated with the stream.

       The filename points to a character string that contains the name of the file to be opened.

       The type is a character string having one of the following values:

	  "r"	    Open for reading

	  "w"	    Truncate or create for writing

	  "a"	    Append; open for writing at end of file, or create for writing

	  "A"	    Append with no overwrite; open for writing at end-of-file, or create for writing

	  "r+"	    Open for reading and writing

	  "w+"	    Truncate or create for reading and writing

	  "a+"	    Append; open or create for reading and writing at end-of-file

	  "A+"	    Append with no overwrite, open or create for update at end-of-file

       The letter "b" can also follow r, w, or a. In some C implementations, the "b" is needed to indicate a  binary  file,  however,  it  is  not
       needed in ULTRIX.  If "+" is used, the "b" may occur on either side, as in "rb+" or "w+b".

       The  routine  substitutes  the named file in place of the open stream.  The original stream is closed, regardless of whether the open ulti-
       mately succeeds.  The routine returns a pointer to the FILE structure associated with stream.

       The routine is typically used to attach the preopened streams associated with stdin, stdout and stderr to other files.

       The routine associates a stream with a file descriptor.	File descriptors are obtained from or which open files but do not return  pointers
       to  a  FILE structure stream.  Streams are necessary input for many of the Section 3s library routines.	The type of stream must agree with
       the mode of the open file.

       When a file is opened for update, both input and output may be done on the resulting stream.  However, output may not be directly  followed
       by  input  without  an  intervening  or and input may not be directly followed by output without an intervening or an input operation which
       encounters end-of-file.

       When a file is opened for append with no overwrite (that is when type is "A" or "A+"), it is impossible to overwrite information already in
       the  file.  The routine may be used to reposition the file pointer to any position in the file, but when output is written to the file, the
       current file pointer is disregarded.  All output is written at the end of the file and causes the file pointer to be  repositioned  at  the
       end  of	the  output.   If  two separate processes open the same file for append, each process may write freely to the file without fear of
       destroying output being written by the other.  The output from the two processes will be intermixed in the file in the order in which it is
       written.

Return Values
       The and routines return a NULL pointer on failure.

Environment
   SYSTEM_V
       When  your  program is compiled using the System V environment, append with no overwrite is specified by using the "a" or "a+" type string,
       and the "A" and "A+" type strings are not allowed.

   POSIX
       In the POSIX environment, the "a" and "a+" strings, and the "A" and "A+" strings specify append with no overwrite.

See Also
       creat(2), dup(2), open(2), pipe(2), fclose(3s), fseek(3s).

																	 fopen(3s)
All times are GMT -4. The time now is 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy