Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Match EOF on newline in a file Post 302589485 by ysrini on Wednesday 11th of January 2012 11:16:27 PM
Old 01-12-2012
Match EOF on newline in a file

Hi,
i have a file where the end-of-file might be at the end of of a valid text line or on a new line

case a)
p q r
s t u <eof>

case b)
p q r
s t u
<eof>

case c)
p q r
s t u
<no data, only carriage return>
<eof>

I have a requirement where <eof> line should not be read if it's on a newline (in a grep command)

I don't want to use tail -1 because that will omit data in case a), and
don't want to ignore blank lines because will lose the blank line after 's t u' in case c)

How do i do this?

Thanks,
-srinivas yelamanchili
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if the file DOES NOT have EOF

Hi, Please help me on this. how to check if the file DOES NOT have EOF ?? I am using ksh for this. (3 Replies)
Discussion started by: BasavarajaKC
3 Replies

2. Programming

How to match n number of newline character(\n) in lex and yacc

Hi , I need to develop a parser which should match something like 1. text a=5 " a=20"; 2. text a=..." a=20"; 3 text a=..." a=20 b=34 c=12 "; I have used this regular expression in my Lex file to generate the tokens: \".\s*.*\s.\" (8 Replies)
Discussion started by: vishwa787
8 Replies

3. Shell Programming and Scripting

eof in data file

Hi, How to detect eof character in a data file? I am reading a data file generated from UNIX. I use java scanner, the scanner's hasNextLine() returns false in the middle of the file. I suspect there is a eof in the middle of the data file. Does anybody know how to check if a file contains eof... (1 Reply)
Discussion started by: redwing
1 Replies

4. UNIX for Dummies Questions & Answers

Match newline character "\n" in lex

Hi everyone! This is my very first post, sorry if I'm not posting in the right category. I'm trying to match a newline "/n" using lex/yacc. For example, print(9,'\n',8) should print 9 8 now do I write a regular expression to match exactly " '\n' " Thanks! (1 Reply)
Discussion started by: code21
1 Replies

5. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

6. Shell Programming and Scripting

sed truncating last line if EOF is not with newline

sed 's|^xyz.abc *= *.*|xyz.abc=60|' /test/myFile.properties > /test/myFile.properties1 myFile.properties has the last line as xyz.abc=23 does not end with newline. When I run this command the last line is truncated if there is no newline character at EOF. Looking for an alternative here. (1 Reply)
Discussion started by: sunn_hps
1 Replies

7. Shell Programming and Scripting

EOF of file

Hi, I ve a file with name "check" in this file "check" has two lines with contents now how to read these files line by line.. i used the code But these doesnt stop with two lines.. So how to set condition that only two lines be read and the program should stop its execution.. Please... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

8. UNIX for Dummies Questions & Answers

Print a newline after first match in line

Hi everyone I have a file where CP occurs both within each line and at the very end: dwer 17 knsdask= * CP hwla 17 h'wopie un CP I would like to separate the line on the first CP to get: dwer 17 knsdask= * CP hwla 17 h'wopie un CP What I have so far is: awk '{for (x=1; x<NF; x++) ... (5 Replies)
Discussion started by: meet77
5 Replies

9. Shell Programming and Scripting

sed to remove newline chars based on pattern mis-match

Greetings Experts, I am in AIX; I have a file generated through awk after processing the input files. Now I need to replace or remove the new-line characters on all lines that doesn't have a ; which is the last character on the line. I tried to use sed 's/\n/ /g' After checking through the... (6 Replies)
Discussion started by: chill3chee
6 Replies

10. Shell Programming and Scripting

Insert a newline after match in files of specific name under some subdirectories?

Hi I'd like to add the newline: \tuser: nobody", or "<TAB>user: nobody to all files named: docker-compose.ymlin subfolders of pwd with names beginning with 10-20. Within these files, I'd like to find the line (there'll only be one) containing: command: celery workerNOTE: As far as... (2 Replies)
Discussion started by: duncanbetts
2 Replies
TextBuffer(3I)						    InterViews Reference Manual 					    TextBuffer(3I)

NAME
TextBuffer - operations on unstructured text SYNOPSIS
#include <InterViews/textbuffer.h> DESCRIPTION
TextBuffer defines common editing, searching, and text movement operations on a buffer of unstructured text. Text positions are specified by an index into the buffer and logically refer to positions between characters. For example, the position referred to by the index 0 is before the first character in the text. Indices can be compared for equality or ordering, but they should not be used to directly access the buffer because TextBuffer might rearrange the text to improve the efficiency of some operations. PUBLIC OPERATIONS
TextBuffer(char* buffer, int length, int size) ~TextBuffer() Create or destroy an instance of TextBuffer. All operations on the text contained in buffer should be performed through TextBuffer functions. The text is assumed to be of length length, and the total available buffer size is size. int Search(Regexp* regexp, int index, int range, int stop) int ForwardSearch(Regexp* regexp, int index) int BackwardSearch(Regexp* regexp, int index) Search for a match with the regular expression regexp, beginning at position index. Search searches the part of the buffer speci- fied by range and stop and returns the index of the beginning of the matched text. Positive values of range specify forward searches, and negative values specify backward searches. In either case, the matched text will not extend beyond the position given by stop. ForwardSearch searches for matches from index to the end of the text and returns the index of the end of the match. Back- wardSearch searches from index to the start of the text and returns the index of the beginning of the match. All three functions return a negative number if there was no match. int Match(Regexp* regexp, int index, int stop) boolean ForwardMatch(Regexp* regexp, int index) boolean BackwardMatch(Regexp* regexp, int index) Attempt to match the regular expression regexp at the position index. Match returns the length of the matching string, or a nega- tive number if there was no match. Matching will not succeed beyond the position given by stop. ForwardMatch looks for a match that begins at index. BackwardMatch looks for a match that ends at index. int Insert(int index, const char* string, int count) int Delete(int index, int count) int Copy(int index, char* buffer, int count) Edit the text in the buffer. Insert inserts count characters from string at the position index. It returns the actual number of characters inserted, which might be less than count if there is insufficient space in the buffer. Delete deletes count characters from the buffer. A positive count deletes characters after index, and a negative value deletes character before index. Delete returns the actual number of characters deleted, which might be less than count if index is near the beginning or the end of the text. Copy copies count characters into buffer. A positive count copies characters after index and a negative count copies charac- ters before index. Count returns the actual number of characters copied. It is the caller's responsibility to ensure that buffer contains sufficient space for the copied text. int Height() int Width() int Length() Return information about the text. Height returns the number of lines in the text, Width returns the number of characters in the longest line, and Length returns the total number of characters. const char* Text() const char* Text(int index) const char* Text(int index1, int index2) char Char (int index) Access the contents of the text. Char returns the character immediately following index. The three Text calls return pointers to character strings representing the text. They make various guarantees about the format of the returned string. With no parameters, Text returns a pointer to a string that contains the entire text of the buffer. With a single parameter the string contains at least the text from index to the end of the line. With two parameters, the returned string contains at least the text between index1 and index2. In any case, the returned string should be considered temporary and its contents subject to change. To maximize efficiency, you should prefer the more restricted forms of Text. int LineIndex(int line) int LinesBetween(int index1, int index2) int LineNumber(int index) int LineOffset (int index) Map between text indices and line and offset positions. LineIndex returns the index of the beginning of line line. LineNumber returns the number of the line that contains index. LineOffset returns the offset of index from the beginning of its containing line. LinesBetween returns the difference between the numbers of the lines containings index1 and index2; a return value of zero indicates that index1 and index2 are on the same line, and a positive value indicates that the line containing index2 is after the line containing index1. Lines are numbered starting from zero. int PreviousCharacter(int index) int NextCharacter(int index) Return the index immediately following or preceding index. The returned value is never before the beginning or after the end of the text. boolean IsBeginningOfText(int index) int BeginningOfText() boolean IsEndOfText(int index) int EndOfText() Return the index of the beginning or end of the text, or query whether index is at the beginning or end of the text. boolean IsBeginningOfLine(int index) int BeginningOfLine(int index) int BeginningOfNextLine(int index) boolean IsEndOfLine(int index) int EndOfLine(int index) int EndOfPreviousLine(int index) Return information about the line structure of the text around index. BeginningOfLine returns the index of the beginning of the line containing index. BeginningOfNextLine returns the index of the beginning of the next line that begins after index. EndOfLine returns the index of the end of the line containing index. EndOfPreviousLine returns the index of the end of the last line that ends before index. The beginning of a line is logically immediately after a newline character, and the end of a line is logically immediately before a newline character. The beginning and end of the text are considered to be the beginning and end of the first and last lines, respectively. boolean IsBeginningOfWord(int index) int BeginningOfWord(int index) int BeginningOfNextWord(int index) boolean IsEndOfWord(int index) int EndOfWord(int index) int EndOfPreviousWord(int index) Return information about the word structure of the text around index. BeginningOfWord returns the index of the beginning of the word containing index. BeginningOfNextWord return the index of the beginning of the nest word that begins after index. EndOfWord returns the index of the end of the word that contains index. EndOfPreviousWord returns the index of the end of the last word that ends before index. A word is defined as a sequence of alpha-numeric characters. The beginning and end of the text are considered to be the beginning and end of the first and last words, respectively. SEE ALSO
Regexp(3I) InterViews 23 May 1989 TextBuffer(3I)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy