3

How does the following code print just a single file?

find "$fdir" -type f -name "${fnam}-*.png" -print0 | awk -v RS='\0' -F'[-.]' '{print $(NF-1), $0}' | cat -vet

which gives me

04 /home/flora/edvart/docs/schimmel-04.png$

But doing find "$fdir" -type f -name "${fnam}-*.png" gives

/home/flora/edvart/docs/schimmel-04.png
/home/flora/edvart/docs/schimmel-05.png
/home/flora/edvart/docs/schimmel-06.png
/home/flora/edvart/docs/schimmel-07.png
/home/flora/edvart/docs/schimmel-08.png
/home/flora/edvart/docs/schimmel-09.png
/home/flora/edvart/docs/schimmel-10.png
/home/flora/edvart/docs/schimmel-11.png
/home/flora/edvart/docs/schimmel-12.png
/home/flora/edvart/docs/schimmel-13.png
/home/flora/edvart/docs/schimmel-1.png
/home/flora/edvart/docs/schimmel-2.png
/home/flora/edvart/docs/schimmel-3.png
9
  • What are the contents inside $fdir? and what is the value of $fnam? Commented Oct 18, 2021 at 5:39
  • 1
    For me works as expected (each file one record / line). Commented Oct 18, 2021 at 5:46
  • fdir: /home/flora/edvart/docs and fnam: schimmel Commented Oct 18, 2021 at 5:50
  • 2
    Is your (unknown) awk able to use \0 as a record separator with the meaning you intend for it? Commented Oct 18, 2021 at 6:05
  • I guess printf 'a\0b\0' | awk -v RS='\0' 1 may tell us something about your awk. Does it print two lines? or just a? Commented Oct 18, 2021 at 6:09

1 Answer 1

8

Only GNU awk and mawk (release 1.3.4 or later) can use \0 as a record separator with the meaning "null character." Older releases of mawk, BSD awk, Busybox awk, Plan 9 awk etc. all treat the string \0 in RS as if RS had been the empty string, i.e., it enables "paragraph mode" (two or more contiguous newlines delimit records).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.