
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tlug] Re: line filtering (was Re: Unidentified subject!)
>> ------------->8-----------------
>>
>>gawk -F" " 'BEGIN { numexp = "[[:digit:]]+"; tmp="" }
>>NR > 0 {
>> if ($1 ~ numexp && tmp != "") { print tmp; tmp="" }
>>}
>>{ tmp = tmp" "$0; }'
>>
>> ------------->8-----------------
>
> Oh, that's gross. And it's also wrong. (Try it! It doesn't work.)
It's work. But really have little mistake - do not display the last line.
So with correction and in shell script:
------[ join_lines.sh ]------->8-----------------
#!/bin/sh
# Usage: join_lines.sh < text_file.txt
#
gawk -F" " '
BEGIN { numexp = "[[:digit:]]+"; tmp="" }
NR > 0 {
if ($1 ~ numexp && tmp != "") { print tmp; tmp="" }
}
{ tmp = tmp" "$0 }
END { if (tmp != "") print tmp; }
'
------------------------------>8-----------------
And once more - do not use awk - it just do not display
anything. Use gawk. Also I was wrong for mawk - it put
everything on one line. The input and output test files
are in the attachements.
--
ISBN: 0060256575 OpenPGP: 0xBE40FF3E
1 some text
text with C/R s
2 and this is the second line
3 text text
text
4 line number 4
and this is also line number 4
5 the last line
1 some text text with C/R s
2 and this is the second line
3 text text text
4 line number 4 and this is also line number 4
5 the last line
Home |
Main Index |
Thread Index