Single command to create multiple empty files(no trailing lines as well). | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-05-2013
Onkar Banerjee Onkar Banerjee is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 17 September 2013, 7:02 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 09-05-2013
smoofy smoofy is offline
Registered User
 
Join Date: May 2010
Last Activity: 9 July 2014, 1:11 AM EDT
Posts: 37
Thanks: 0
Thanked 6 Times in 6 Posts
It depends on what file names you would like to have but for files 1-9 you could go with:

Code:
for i in `seq 1 9`; do echo "" > ./$i; done

Sponsored Links
    #3  
Old 09-05-2013
karthikram karthikram is offline
Registered User
 
Join Date: May 2013
Last Activity: 21 May 2014, 10:22 AM EDT
Posts: 35
Thanks: 26
Thanked 0 Times in 0 Posts
You might have heard of touch command,

You can use
Code:
touch empty_file.txt

this will craete the file , if already exists it wont create the file or empty the file, you may create the same in anywhere of your script.

Thanks,
Regards,
karthikram
    #4  
Old 09-05-2013
Onkar Banerjee Onkar Banerjee is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 17 September 2013, 7:02 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
touch, cat will not be working for me.. however, i am trying some options with the echo -n actually..

---------- Post updated at 03:45 AM ---------- Previous update was at 03:40 AM ----------

the thing is,
i want to create multiple files without any trailing spaces at all, but script may fail in between and in that case , it would be run again, then i want the old contents to be flushed out of the created files so they are empty again(no trailing spaces) .. now ofcourse i can do it by some code snippet but what i am looking for is a Unix command only to remove older contents if already existing or create new one if not(without any trailing spaces).
Sponsored Links
    #5  
Old 09-05-2013
MR.bean MR.bean is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 18 February 2014, 2:40 AM EST
Posts: 79
Thanks: 0
Thanked 16 Times in 16 Posts
It's strange that you cannot use cat touch >, I'm not sure what type of environment you are using that disallow you to use those typical commands. Use perl if you can


Code:
seq 1 5 | perl -lne '{ open(F, ">$_"); close(F); }'

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help combining txt files w/ multiple lines into csv single cell - also need data merge jetsetter UNIX for Dummies Questions & Answers 2 02-04-2013 09:12 AM
Parse multiple lines of a command output into a single variable? shell_newbie Shell Programming and Scripting 2 03-30-2012 09:07 AM
Empty out multiple files with a single command? Validatorian Shell Programming and Scripting 4 01-16-2012 04:08 PM
Grep multiple strings in multiple files using single command gagan4599 UNIX for Dummies Questions & Answers 2 01-19-2011 06:22 AM
Split the single file lines into multiple files subbarao25 Shell Programming and Scripting 15 05-07-2010 02:58 AM



All times are GMT -4. The time now is 11:16 AM.