awk, sed, perl assistance in outputting formatted file

Hello,

Please advise. Scoured this site, as well as google for answers. However if you do not know what to search for, it's a bit hard to find answers.

INPUT:

ACTASS=
802
BASECOS=
279
COSNCHG=
3
CUSCOS=
52
UPLDCOS=
2

DESIRED OUTPUT:

ACTASS=802
BASECOS=279
COSNCHG=3
CUSCOS=52
UPLDCOS=2

If solved can someone please direct in the correct route for a newbie scripter to find this answer. I am think search and then append bottom line to = sign.

Thank you to anyone that takes the time to explain. I have gained so much useful knowledge at this site.

Regards,
Abacus

awk '{ORS=(/=/)?X:RS}1' file

:wink:

Holy Crap,
Amazing. I hate to ask you. However I have been studying awk and I will try to look this up. However can you please break this down.

I am thankful if you choose not too.

Thanks,

Abacus

PS: I am out of bits to award you. I will try however.

HEHE

SOLVED

If you want to take the shortcut take a look at awk cheat sheet
What I did was just playing with ORS value, between RS and X(has no value, is NULL).

Success :wink:

while read -r line
do
    case "$line" in
        *=)
            printf "%s" $line
            read d
            echo $d
            ;;
    esac
done <"file"

Another one:

while read -r line
do
	case "$line" in 
		*=) printf "%s"   $line;;
		*)  printf "%s\n" $line;; 
	esac
done < file
sed 'N;s/=\n/=/' infile
sed 'N;s/\n//' infile

i think u can use only printf :slight_smile: no fancy commands

printf %s%s"\n" $(cat filename)

Here's one way to do it with Perl:

$
$ cat f4
ACTASS=
802
BASECOS=
279
COSNCHG=
3
CUSCOS=
52
UPLDCOS=
2
$
$ perl -lne '/=$/ ? printf : print' f4
ACTASS=802
BASECOS=279
COSNCHG=3
CUSCOS=52
UPLDCOS=2
$
$

And a tad shorter:

perl -lnE '/=$/ ? printf : say' f4

Or:

perl -lne 'BEGIN{undef $/} s/=\n/=/g; print' f4
perl -lne '$.%2==1 ? printf : print' f4

tyler_durden

:wink:

printf %s%s"\n"  $(< file)

My bash can do that , no UUoC :wink:

And so can ksh and zsh, posix can't though.

xargs -n2 < urfile
xargs -n2 < urfile | tr -d ' '

Thanks guys,

I now have to spend the rest of the weekend learning all your great code.

Thanks again to all who assisted.

Abacus