While or For with looping contructs? to create files from contents of a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While or For with looping contructs? to create files from contents of a text file
# 1  
Old 05-23-2012
Please help on how to create files from contents of a text file??? whats the best approach

Hi so far I created this script:

Code:
vi loop.beta.sh
 
for i in `cat extract.filenames.tabc`
do
        echo $i 
done>$i

===
This is the original text file.
Code:
[localuser@localhost ~]$ more tabc.txt
-rwx------- 1 alice   staff     1586  2010-11-05 02:27 request-key
.conf
-rwx------- 1 ted   staff     126  2011-04-29 13:54 cvs-pserver.co
nf
-rwx------- 1 carol   staff     644  2011-03-06 21:58 ts.conf
-rwx------- 1 alice   staff     17268  2011-04-29 13:54 devscripts
.conf
-rwx------- 1 bob   staff     34  2011-04-29 05:18 ld.so.conf
-rwx------- 1 bob   staff     92  2011-04-23 02:45 host.conf
-rwx------- 1 bob   staff     4794  2011-04-22 12:14 hdparm.conf
-rwx------- 1 bob   staff     1308  2011-04-19 02:06 kerneloops.co
nf
-rwx------- 1 bob   staff     552  2011-04-13 15:01 pam.conf
-rwx------- 1 bob   staff     322  2011-03-22 10:50 blkid.conf
-rwx------- 1 bob   staff     2724  2011-02-06 22:18 reportbug.con
f
-rwx------- 1 bob   staff     166  2011-01-04 22:46 tidy.conf
-rwx------- 1 bob   staff     1132  2010-12-12 12:47 smi.conf
-rwx------- 1 bob   staff     884  2010-11-05 00:56 insserv.conf
-rwx------- 1 alice   staff     168  2011-06-26 11:38 kernel-img.c
onf
-rwx------- 1 alice   staff     512  2011-04-29 05:27 nsswitch.con

===

#I then spliced out the last field in order to extract filenames
# Now I don't know how I can make files consecutively line by line using # these as their filenames???
# Should I use touch? Please help!

Code:
[localuser@localhost ~]$ more extract.filenames.tabc
request-key.conf
cvs-pserver.conf
ts.conf
devscripts.conf
ld.so.conf
host.conf
hdparm.conf
kerneloops.conf
pam.conf
blkid.conf
reportbug.conf
tidy.conf
smi.conf
insserv.conf
kernel-img.conf
nsswitch.conf
ca-certificates.conf
ntp.conf
updatedb.conf
libao.conf
deluser.conf
uniconf.conf
sysctl.conf
mtools.conf
preload.conf
netscsid.conf
resolv.conf
pnm2ppa.conf
gai.conf
debconf.conf
cowpoke.conf
logrotate.conf
ffserver.conf
sensors3.conf
popularity-contest.conf
cvs-cron.conf
adduser.conf

===

Please help on how to create files in home directory with the contents of line by line of the above extracted files???

Thank you

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.


---------- Post updated at 02:25 AM ---------- Previous update was at 02:14 AM ----------

Do I have to clarify or retype this post so I someone can take a look at it?

Last edited by wolf@=NK; 05-23-2012 at 06:21 AM.. Reason: clarify title and hope someone would give suggestion thanks
# 2  
Old 05-23-2012
There are several approaches possible. This way you can leave out the cat-command. Try this:
Code:
while read LINE; do touch $LINE; done < extract.filenames.tabc

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 05-23-2012
thanks

It doesn't have to be while?? I was thinking before that I might have to make looping contruct with something like >i++ and i=1 or something but I don't know how to apply it to these...

I will try this method though

Thanks again!Smilie
# 4  
Old 05-23-2012
In fact a combination of your first step with cut and the touch can look like this:
Code:
# awk '{print $NF}' infile| xargs touch

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a text file into smaller files with awk, how to create a different name for each new file

Hello, I have some large text files that look like, putrescine Mrv1583 01041713302D 6 5 0 0 0 0 999 V2000 2.0928 -0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 5.6650 0.2063 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 3.5217 ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

Need help with looping through file contents

Hi, I have a several files with ".out" extension in a folder and each file has the below like contents .... appname: wonder1 ..... logname78.log logname88.log ..... CAP: 2 ..... appname: wonder54 ...... logname28.log logname58.log logname54.log ..... CAP: 3 ..... (4 Replies)
Discussion started by: mohtashims
4 Replies

3. UNIX for Dummies Questions & Answers

Looping through the contents of array for output name

Hi all, I am trying to loop through the string contents of an array, to add it during the saving of the output files. I am trying this code to print each column and save it to unique file name, but it doesn't work. Thanks for any help. fnam=(japan usa uk) alldata.dat contained sample data... (1 Reply)
Discussion started by: ida1215
1 Replies

4. Programming

Looping and caling in a text file C++

Hi , I am trying to create a loop to call in the entries from the text file named Set. The entries of Set.txtare : 1 2 3 2 4 5 and so on .. (64 such combinations) it basically means the first combination for testing is 1 2 3 and next has to be 2 4 5 and so i have 64 such entries defined... (1 Reply)
Discussion started by: siya@
1 Replies

5. UNIX for Dummies Questions & Answers

Looping/Reading file contents not working

Hi, I am doing something basic, but I am missing something. Im trying to read the contents of a file and taking those values and connecting to a database. However, it only connect to one (or reads in) value and then exists. Here is what it looks like: listname.txt db1 db2 db3 Script:... (15 Replies)
Discussion started by: DBnixUser
15 Replies

6. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

7. Shell Programming and Scripting

Need help in writing a script to create a new text file with specific data from existing two files

Hi, I have two text files. Need to create a third text file extracting specific data from first two existing files.. Text File 1: Format contains: SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010 some text ............so on...and somwhere text like: Record 1:... (1 Reply)
Discussion started by: shashi143ibm
1 Replies

8. Shell Programming and Scripting

Create multiple text file from a single text file on AIX

Hi I need to create multiple text files from onc text file on AIX. The data of text files is as below: ********************************************** ********************************************** DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009 Copyright (c) 1982,... (11 Replies)
Discussion started by: lodhi1978
11 Replies

9. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

10. Shell Programming and Scripting

Looping through each line of text file

Dear all, I have a text file like below. eg.txt abcd efgh ijkl mnop I need a script, which should read the text file eg.txt and assign each line as a parameter. This , i wil use further to pass it a java command to invoke. All inside a for loop Need your help on this. With... (2 Replies)
Discussion started by: KrishnaSaran
2 Replies
Login or Register to Ask a Question