Question

I want to read whole file not per lines. How to change field separator to eof-symbol?

I do:

awk "^[0-9]+∆DD$1[PS].*$" $(ls -tr)

$1 - param (some integer), .* - message that I want to print. There is a problem: message can contains \n. In that way this code prints only first line of file. How can I scan whole file not per lines? Can I do this using awk, sed, grep? Script must have length <= 60 characters (include spaces).

Was it helpful?

Solution

Assuming you mean record separator, not field separator, with GNU awk you'd do:

gawk -v RS='^$' '{ print "<" $0 ">" }' file

Replace the print with whatever you really want to do and update your question with some sample input and expected output if you want help with that part too.

The portable way to do this, by the way, is to build up the record line by line and then process it in the END section:

awk '{rec = rec (NR>1?RS:"") $0} END{ print "<" rec ">" }' file

using nf = split(rec,flds) to create fields if necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top