AWK printf help

Target file contains short text (never more than 1 line) and filenames.

The format is, e.g.,:

TEXT1
filename1
TEXT2
TEXT3
filename3dddd
filename3dddd
TEXT4
filename4
TEXT5
filename5dddd
filename5dddd
filename5

where dddd is a random 4-digit whole number.

Desired output:

TEXT1 filename1
TEXT2
TEXT3 filename3dddd
TEXT3 filename3dddd
TEXT4 filename4
TEXT5 filename5dddd
TEXT5 filename5dddd
TEXT5 filename5

How do you differentiate filename and text?

filename has an extension: filename.ext
TEXT is all uppercase
filenames are all lowercase
also there is a trailing special character only on the end of each TEXT string that is not present in any filename

hope that helps :slight_smile:

awk ' !/.ext/{ txt=$0; next } { print txt " " $0 } ' file

This is beautifully simple. Thank you anbu23.