1

I would like to create files from the following list.

There is no problem if the list doesn't have a space ... but the problem is it has a space

user@linux:~$ cat file.txt 
Apples
Bing Cherry
Crab Apples
Dragon Fruit
user@linux:~$ 

Before

ser@pc:~$ ls -l
total 4
-rw-r--r-- 1 user user 44 Jun   9 14:06 file.txt
user@linux:~$ 

xargs touch

user@linux:~$ cat file.txt | xargs touch 
user@linux:~$ 

Instead of creating Apples, Bing Cherry, Crab Apples, Dragon Fruit, the command producing these output.

After

user@linux:~$ ls -l
total 4
-rw-r--r-- 1 user user  0 Jun   9 14:11 Apples
-rw-r--r-- 1 user user  0 Jun   9 14:11 Bing
-rw-r--r-- 1 user user  0 Jun   9 14:11 Cherry
-rw-r--r-- 1 user user  0 Jun   9 14:11 Crab
-rw-r--r-- 1 user user  0 Jun   9 14:11 Dragon
-rw-r--r-- 1 user user 44 Jun   9 14:06 file.txt
-rw-r--r-- 1 user user  0 Jun   9 14:11 Fruit
user@linux:~$ 

What should I do to handle space in this situation?

1 Answers1

1

With the GNU implementation of xargs, you can specify newline as the separator with the -d/--delimiter option:

xargs --no-run-if-empty --delimiter='\n' --arg-file=file.txt touch --

With short options:

xargs -r -d '\n' -a file.txt touch --
Jasen
  • 3,761