How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts.

Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea.

In short, I dump a site via lynx and pipe the output in a file. I need to cut - the first line only -near the 15th column, by piping aswell.

The Information I need is always in this area 1 - 15 col.

A word or chars which are together should not be cut at this pont. So the cut should take place after the next blank (space).

example
123456789012345678901234567890 <-- column
balah bb 213112312 12321 <-- random information

balah bb 213112312 <-the result should be this

I tried several approaches with fold and awk and cut, but the results were not ok.

the information below the first line must stay untouched and sould not be wrapped aswell. Thats the problem I have.

i don't understand.. show an actual sample of the file and output desired.

this one:

balah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 21b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311

should look like this:

balah bb 213112312
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 21b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311

the data is random and can be anything...

ok so you are only processing the first line. If you have Python,

#!/usr/bin/env python
f=open("file")
firstline=f.readline().strip()[:19]
print firstline
for line in f: print line.strip()
f.close()

output:

# ./test.py
balah bb 213112312
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 21b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311
                                            

else:

# awk 'NR==1{print substr($0,1,19);next}1' file

wow, thanks for the fast answer.

# awk 'NR==1{print substr($0,1,19);next}1' file

This cuts the line correct if the blank is at column 19. What if the line is random so that the output for the 2 examples should look like this, a cut near column 15:

ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312

b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
b 213112312 12321 or
b 213112312

Maybe something like this:

$
$ cat input.txt
balah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 21b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311
$
$ perl -ne '{if ($. eq 1){print substr($_,0,index($_," ",14))."\n"} else {print}}' input.txt
balah bb 213112312
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 21b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311b 213112b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
ah bb 21311
$
$

tyler_durden

$
$ cat input1.txt
ah bb 213112312 12321 balah bb 213112312 12321 balah bb 213112312 123
$
$ perl -ne '{if ($. eq 1){print substr($_,0,index($_," ",14))."\n"} else {print}}' input1.txt
ah bb 213112312
$
$
$ cat input2.txt
b 213112312 12321 balah bb 213112312 12321 balah bb 213112312 12321
$
$
$ perl -ne '{if ($. eq 1){print substr($_,0,index($_," ",14))."\n"} else {print}}' input2.txt
b 213112312 12321
$
$

tyler_durden

This one is absolutely perfect for my case. I have to take a closer look, what it does...

Thanx alot!