Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split a text line in UNIX file

Status
Not open for further replies.

alhassani54

Programmer
Aug 1, 2002
27
GB
Hi

I have a text UNIX file, the file contains one line and the line contains from 0 to thousands of characters.
Firstly, I want to check the line should not be larger than 20,000 characters.
Secondly, if the line is greater than 20,000 characters I want to split it to lines in a new file. Each line must not be greater than 20,000 characters.

Any help will be appreciated.
 
Hi

Assuming that only the first line of the input file has to be checked but all lines has to be wrapped.
Code:
[ `head -1 /input/file | wc -c` -gt 20000 ] && fold -w 20000 /input/file > /output/file
But if is sure that the input file always has only one line is more simple.
Code:
[ `wc -c < /input/file` -gt 20000 ] && fold -w 20000 /input/file > /output/file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top