Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shell script to get the end of line

 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anybody tell me to get the end of line in a file using shell script?

--Yug

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

use 'cat filename | tail -1'
 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hope,
use 'cat filename | tail -1' - this command returns the end of file.

I want to get the end of each line in a file to parse some data.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want to get the end of each line in a file to parse some data.


what do you mean by that . if i understood tat , end of each line will ultimately return you the entire file
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean getting the last line of a file?

 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou for the reply.
Let me explain my scenario:

For example, i have the following lines in a file:

"The split command reads input from a file or the standard input and creates multiple output files. Thus it is suitable as the last stage of the pipeline.
Each file contains n lines of the original. If you do not provide n,
split uses the value of 1000. You can split file into chanks on one line per file using n=1. "



I want to split this files, into multiple files based on some byte size - say 5k

split -b 5k <source file>

While splitting, say for ex, if the first 5k size ends like in the mid of any line

"The split command reads input from a file or the standard input and creates multiple output files. Thus it is suitable as the last stage of the pipeline.
Each file contains ",


i would like to get till the end of this line

I mean till " Each file contains n lines of the original. If you do not provide n,"

Is this possible??
Hope i am clear
-- Yuga

 
Ananth Chellathurai
Ranch Hand
Posts: 349
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be possible. Read the file line by line and write it to another file. Check the new file size after writing eachline, when it reaches some limit start writing the remaining to a new file.

For reading line by line.
For finding file size.
 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thankyou..

But one setback here is : My source file is bigger -around 50000 lines. So, in such a big file, there is a possibility of performance issue.

So is there any other solution, to do this .Without writing it into another file.

Thanks in advance,
--yuga
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic