WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: No output showing: 'find /dir | tail -n +2'  (Read 384 times)

Offline Santos

  • Jr. Member
  • **
  • Posts: 63
No output showing: 'find /dir | tail -n +2'
« on: September 06, 2021, 04:53:34 PM »
Hello

I have a folder as follows:

Code: [Select]
prueba/
        uno/
        dos/
        tres/

What I want to do is create on each one of the folders a TXT file with the name of its parent folder, like so:

Code: [Select]
prueba/
        uno/uno.txt
        dos/dos.txt
        tres/tres.txt


For it I'm trying to use  find  but when I execute the following, nothing happens:

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9580
Re: No output showing: 'find /dir | tail -n +2'
« Reply #1 on: September 06, 2021, 05:45:27 PM »
Hi Santos
Try the command in the attached file.

Offline Santos

  • Jr. Member
  • **
  • Posts: 63
Re: No output showing: 'find /dir | tail -n +2'
« Reply #2 on: September 07, 2021, 01:20:59 PM »
Hi Rich

Thank you.

I was about to post the remaining of the post but got a message about the server being down.

In 'for loops' I got errors when folder's names are not in ASCII (or with a space). But  find  will take care of special characters without issues because I can always use inodes for file processing (delete, rename, move, copy, etc).

But I will go ahead a try with the code you share with me.

Also, I'm curious about why the code I attached is not showing up any output.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 9580
Re: No output showing: 'find /dir | tail -n +2'
« Reply #3 on: September 07, 2021, 01:47:54 PM »
Hi Santos
For starters,  tail  is the wrong command to strip the leading  ./  characters.
Try something like this:
Code: [Select]
busybox find . -type d -maxdepth 1 | cut -c 3-

Offline Santos

  • Jr. Member
  • **
  • Posts: 63
Re: No output showing: 'find /dir | tail -n +2'
« Reply #4 on: September 07, 2021, 02:14:38 PM »
Thank you.

What I am trying to remove is the current working directory (the dot) showing in  find's  ouput:

Without the dot  and code tags because I'm getting a server error.

(dot)
./uno
./dos
./tres


That's why I wanted to use  tail  , but  cut  will be very handy.

Offline Santos

  • Jr. Member
  • **
  • Posts: 63
Re: No output showing: 'find /dir | tail -n +2'
« Reply #5 on: September 07, 2021, 08:31:40 PM »
I found the answer, something not present in the --help output.

Code: [Select]
busybox find . -not -path .

Same result if the following is used:
Code: [Select]
busybox find . -mindepth 1

That will do the trick, now I'm just left with my question about  tail  not processing  stdout  of  find.
« Last Edit: September 07, 2021, 08:37:28 PM by Santos »

Offline Santos

  • Jr. Member
  • **
  • Posts: 63
Re: No output showing: 'find /dir | tail -n +2'
« Reply #6 on: September 10, 2021, 10:56:15 AM »
What happened here is that  tail  is processing one line at time (due to the implicit loop in find), exactly what I'm telling it to do. Is a formatting error.