Link to home
Create AccountLog in
Avatar of masa2004
masa2004

asked on

Looking for a unix command to extract specific lines for cygwin

Hi, experts,

I'd like to get a grep or sed command which can run on cygwin in order to do
"if a first column of the line is not numeric, concat the current line and the previous line"
The columns are separated by tabs.

For example,
000001<tab>aaaa<tab>bbbbb<tab>
000002<tab>cccc<tab>dd<tab>
ddd<tab>
000003<tab>eeee<tab>fffff<tab>

I just want to get
000002<tab>cccc<tab>ddddd<tab>

Thanks,
Masa
Avatar of scarcas
scarcas

Can you not use awk?
Avatar of masa2004

ASKER

>Can you not use awk?
Yes, I can, however I am new to use unix command yet.
Can you give me the example ?

Masa
Avatar of ozo
I'm assuming when you say you want to get
000002<tab>cccc<tab>ddddd<tab>
you also want to get
000001<tab>aaaa<tab>bbbbb<tab>
and
000003<tab>eeee<tab>fffff<tab>

perl -0777 -pe 's/\s*\n([\D])/$1/g' < inputfile > outputfile
>perl -0777 -pe 's/\s*\n([\D])/$1/g' < inputfile > outputfile
It made the same string as the input file.

Masa.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thank you, ozo.

I could solve the problem.