Computing.Net > Forums > Unix > Create an extended file from a file

Create an extended file from a file

Reply to Message Icon

Original Message
Name: hismail
Date: June 8, 2005 at 07:11:40 Pacific
Subject: Create an extended file from a file
OS: Sco Openserver
CPU/Ram: 2 gig
Comment:

Hi
I want to create a file eg: newfile.txt
from myfile.txt
data inside myfile.txt :
01 abc
02 abc
Need this in newfile.txt:
01 abc
02 abc
03 abc
04 abc
& so on upto 99 abc


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: June 8, 2005 at 10:38:36 Pacific
Reply: (edit)

There are any number of ways to do this:

#!/bin/ksh
integer x=9

cp myfile.txt newfile.txt

stop=99
start=2
while (($start < $stop))
do
((start+=1))
if (( $start <= $x ))
then
printf "0%d abc\n" $start >> newfile.txt
else
printf "%d abc\n" $start >> newfile.txt
fi
done


Report Offensive Follow Up For Removal

Response Number 2
Name: hismail
Date: June 9, 2005 at 04:28:52 Pacific
Reply: (edit)

Thanks Nails


Report Offensive Follow Up For Removal

Response Number 3
Name: hismail
Date: June 9, 2005 at 04:38:48 Pacific
Reply: (edit)

Hi Nails
I get a syntax error at line 15: `done' unexpected



Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: June 9, 2005 at 06:07:24 Pacific
Reply: (edit)

I'm not having a problem. I even cut-and-pasted the code posted here into my Solaris system, and it works.

Are you sure that you didn't drop the 'do' statement:

while (($start < $stop))
do
.
.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Create an extended file from a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge