>3) How do i write to a new file everytime the script is executed. The name is not very important.
for this purpose, you can also use mktemp ... man mktemp
any feedback ?
Main Topics
Browse All TopicsI am new to shell scripts so please excuse my newbie questions or mistakes
1) How do i read a file into a shell script variable.? While reading i should preserve all special characters, tabs, carriage returns etc, ineffect everything that is there in that file should be kept as is. A text file needs to be created by this script which will further be processed by a Java program.
2) Once i read the file, i need to check if the first 2 characters are **.
3) How do i write to a new file everytime the script is executed. The name is not very important.
Thank you all for your help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
There are two powerful utilties that you can use.
Sed and Awk. I advise you to go to google and do a search on shell scripting tutorial and simply walk through the step by step guides that you find.
Second, go to google and do a search on Sed and Awk tutorial and work through those.
What you are trying to achieve is relatively simple, and could probably get what you need within a few hours of going through the tutorials.
Business Accounts
Answer for Membership
by: sunnycoderPosted on 2003-10-22 at 02:54:05ID: 9597572
>How do i read a file into a shell script variable.?
for i in `cat filename`
or you can use
cat filename | while read line
>While reading i should preserve all special characters, tabs, carriage returns etc, ineffect everything that is there
>in that file should be kept as is.
first method I listed will not preserve newlines and other formatting while second one will
whether you should preserve them or not depends on your application needs
>A text file needs to be created by this script which will further be processed by a Java program.
why not use cp if you are simply copying it !!
>2) Once i read the file, i need to check if the first 2 characters are **.
use grep ^** or sed if you wish to replace them ... more details will be helpful
>3) How do i write to a new file everytime the script is executed. The name is not very important.
a simple way could be to keep a count in a file ... increment this count everytime you write to a newfile
generate name as
newfile.<count from file>