Solved

File reading in unix

Posted on 2000-03-09
9
252 Views
Last Modified: 2010-04-21
Does Unix have any function that would read a line fron file, stripping the newline character?
0
Comment
Question by:apaazue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

by:apaazue
ID: 2601078
Thanks
/apaazue
0
 
LVL 84

Expert Comment

by:ozo
ID: 2601269
#include <stdio.h>
char *gets (char *s);
0
 

Author Comment

by:apaazue
ID: 2602183
I don't think gets()function will do it , since it is not used for file reading. I think fgets function is used for file reading line by line,but it does not strip the newline character from the end of string.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 84

Expert Comment

by:ozo
ID: 2603163
It can be used for files if the file is opened to stdin.
Or you could fgets and then remove the \n yourself, or
fscanf("%[^\n]"
0
 
LVL 12

Expert Comment

by:tel2
ID: 2604104
apaazue,

I usually do it using:
  tr -d "\12" <infile >outfile
ie: TRanslate -Deleting ASCII(12 (octal), ie: newline).

That makes outfile which = infile with no newlines.  Is that what you're wanting?
0
 

Author Comment

by:apaazue
ID: 2605384
Let me give some code here, so that it will help in exactly understanding what i want.
fgets(line,MAXBUFF,fd);
I am using the above function to read a file line by line. I am doing a Client/Server program. I have to send each line to server as message. every time i have to strip the newline character and send it. Is there any way or any function that would directly read a line from file stripping the '\n' character.
0
 
LVL 84

Accepted Solution

by:
ozo earned 25 total points
ID: 2605498
#define str(s) #s
#define xstr(s) str(s)
fscanf(fd,"%" xstr(MAXBUFF) "[^\n]",line);
/* but it may be easier to strip the '\n' character yourself */
strtok(line,"\n");
0
 
LVL 5

Expert Comment

by:paulqna
ID: 2606272
C programming is nice but has anyone here heard of awk gawk or sed??
0
 

Author Comment

by:apaazue
ID: 2606355
Thanks
/apaazue
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question