separate old entries

Hi I have a file

Stomach
qwe
wer
qwew
Liver
sdfjk
shdf
jkasfhd

I want expected out shuld be in such a way that bold letters shuld comein front of non bold letter

qwe              Stomach
wer              Stomach
qwew          Stomach
sdfjk            Liver
shdf           Liver
jkasfhd        Liver

Show your efforts please. Any answers before that will be moderated.

1 Like

bold string starts with capital char

actually all bold strings are capital

Stomach is actually STOMACH
Liver is actually LIVER

I didnt realise it in my input that I m writing only first char as capital but in input all bold characters are capital

@raj_saini20:

Hi Raj,

I tried this

awk '($1 ~ /[A-Z]/){x=$1;next}{print $1,x}' filename

but it's not working properly it shows just three names in output which does nto contain any information.

I have a long list of file like this

STOMATOLOGICAL PREPARATIONS
Doxycycline 
Clotrimazole 
Triamcinolone 
Epinephrine 
Amphotericin B 
Hydrocortisone 
DRUGS FOR ACID RELATED DISORDERS
Pantoprazole 
Omeprazole 
Sucralfate 
Lansoprazole 
Cimetidine 
Nizatidine 

And, I need the output like this

Doxycycline    STOMATOLOGICAL PREPARATIONS
Clotrimazole     STOMATOLOGICAL PREPARATIONS
Triamcinolone    STOMATOLOGICAL PREPARATIONS
Epinephrine        STOMATOLOGICAL PREPARATIONS
Amphotericin B    STOMATOLOGICAL PREPARATIONS
Hydrocortisone      STOMATOLOGICAL PREPARATIONS

Pantoprazole          DRUGS FOR ACID RELATED DISORDERS
Omeprazole            DRUGS FOR ACID RELATED DISORDERS
Sucralfate              DRUGS FOR ACID RELATED DISORDERS
Lansoprazole           DRUGS FOR ACID RELATED DISORDERS
Cimetidine                DRUGS FOR ACID RELATED DISORDERS
Nizatidine                DRUGS FOR ACID RELATED DISORDERS
awk '{y=$0;gsub(" ","",y);if(y ~ /^[A-Z]*$/){x=$0;next};print $0,x}' filename

output is

Doxycycline  STOMATOLOGICAL PREPARATIONS
Clotrimazole  STOMATOLOGICAL PREPARATIONS
Triamcinolone  STOMATOLOGICAL PREPARATIONS
Epinephrine  STOMATOLOGICAL PREPARATIONS
Amphotericin B  STOMATOLOGICAL PREPARATIONS
Hydrocortisone  STOMATOLOGICAL PREPARATIONS
Pantoprazole  DRUGS FOR ACID RELATED DISORDERS
Omeprazole  DRUGS FOR ACID RELATED DISORDERS
Sucralfate  DRUGS FOR ACID RELATED DISORDERS
Lansoprazole  DRUGS FOR ACID RELATED DISORDERS
Cimetidine  DRUGS FOR ACID RELATED DISORDERS
Nizatidine DRUGS FOR ACID RELATED DISORDERS

is that ok

Hi Raj,

Yes, it's working fine. Thank you very much.

Mani

Alternatively:

awk '/^[A-Z ]*$/{p=$0; next} $0=$0 FS p' infile