Create empty files from a list on file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create empty files from a list on file
# 1  
Old 11-16-2013
Create empty files from a list on file

Hello Guys.

Please I would like to create empty files from a list

In file1 will be the followin values, so i will like to create for each name a empty file.
file1
Code:
2191off-r0.sps
2192off-r0.sps
2193off-r0.sps
2194off-r0.sps
2195off-r0.sps

So I need to get 5 empty files.

Thanks for your help Smilie
# 2  
Old 11-16-2013
use touch command
# 3  
Old 11-16-2013
To extend on raj's suggestion, try a while read loop:
Code:
while read file; do
  touch "$file"
done < file1


Last edited by Scrutinizer; 11-16-2013 at 01:12 PM..
# 4  
Old 11-16-2013
Hi Scrutinizer...
(Longhand using OSX 10.7.5, default bash terminal.)

What is wrong with this method:-
Code:
Last login: Sat Nov 16 15:01:56 on ttys000
AMIGA:barrywalker~> echo "2191off-r0.sps
> 2192off-r0.sps
> 2193off-r0.sps
> 2194off-r0.sps
> 2195off-r0.sps" > /tmp/file
AMIGA:barrywalker~> while read filenames; do > /tmp/$filenames; done < /tmp/file
AMIGA:barrywalker~> ls -l /tmp/219*
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2191off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2192off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2193off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2194off-r0.sps
-rw-r--r--  1 barrywalker  wheel  0 16 Nov 15:03 /tmp/2195off-r0.sps
AMIGA:barrywalker~> _

Surely this would be quicker as the touch command is not being executed...
Or am I missing something?
This User Gave Thanks to wisecracker For This Post:
# 5  
Old 11-16-2013
Nothing, you are right, using > would be more efficient than using touch.
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-16-2013
Thanks to all for youSmilier help
# 7  
Old 11-16-2013
What about
Code:
touch $(< file)
-rw-r--r-- 1 c c    0 Nov 16 19:49 2191off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2192off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2193off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2194off-r0.sps
-rw-r--r-- 1 c c    0 Nov 16 19:49 2195off-r0.sps

, as touch may have many parameters (up to LINE_MAX?)...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Linux

How to create new empty utf8 file for appending?

Hey i try to create empty text file with utf-8 encoding without success what is the right way to do this ? tried with touch test.txt iconv -f UTF-8 -t UTF-8 test.txt or iconv -f latin1 -t UTF-8 test.txt (8 Replies)
Discussion started by: umen
8 Replies

3. Shell Programming and Scripting

Create a list of missing files

Hello Guys I have a big list of files in one directory. And Some are missing . Example ls -l 2191off-r0.sps 2193off-r0.sps 2194off-r0.sps 2197off-r0.sps 2198off-r0.sps 2200off-r0.sps I would like to create a file with the list only missing files. Or if is possible to create in ... (4 Replies)
Discussion started by: jiam912
4 Replies

4. Shell Programming and Scripting

Single command to create multiple empty files(no trailing lines as well).

Hi, i need a single command to create multiple empty files(no trailing lines as well) and empty the files if already existing. please let me know or if this has been ansered, if some ocan share the link please, thanks > newfile.txt or :> newfile.txt do not work (4 Replies)
Discussion started by: Onkar Banerjee
4 Replies

5. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

6. UNIX Desktop Questions & Answers

how to create empty wav file

Dear All, Kindly explain me a command in unix to create a empty wav file with example. Thanks in Advance! (1 Reply)
Discussion started by: thillai_selvan
1 Replies

7. Shell Programming and Scripting

Create files from a list and then populate them

I have a list of filenames that I want created - they must be created via a certain naming convention due to the software I'm using. Once they are created I have another file that will be used to populate them with data. So far this is what I have: #For each line in text file "foo_txt" create... (2 Replies)
Discussion started by: MaindotC
2 Replies

8. Shell Programming and Scripting

create diffrent files based on other file and parameters list

I would like ot create shell script/ bash to create diffrent files based on a file and parameters list. Here is the detail example: I have a textfile and four static parameter files (having ‘?'). mainfile.txt has below records (this count may be more than 50) A200001 A200101 B200001... (9 Replies)
Discussion started by: raghav525
9 Replies

9. Shell Programming and Scripting

simultaneously create three empty files?

I can't get touch to simultaneously create three empty files file1, file2, file3. I tried:$ touch filebut all I got was one file:$ fileWhat did I do wrong? (4 Replies)
Discussion started by: na5m
4 Replies

10. UNIX for Dummies Questions & Answers

How will you list only the empty lines in a file (using grep)

How will you list only the empty lines in a file (using grep) (1 Reply)
Discussion started by: JosephGerard
1 Replies
Login or Register to Ask a Question