Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to `awk` print a space-separated field which contains space characters?

I am trying to print the list of all files and folders including hidden files:

ls -al | awk -F' ' '{print $9}' | xargs do_something

However, some of the files and/or folders contain space characters. How could I achieve this? Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

$ find . -mindepth 1 -maxdepth 1 -printf "%P\n"|xargs -i sh -c 'echo found: "{}"'
found: file2
found: folder 2
found: folder
found: file 1

$ ls |awk '{print}'|xargs -i sh -c 'echo rm -r \""{}"\"'
rm -r "file 1"
rm -r "file2"
rm -r "folder"
rm -r "folder 2"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading