Link to home
Start Free TrialLog in
Avatar of ns11
ns11

asked on

Reading, writing and substring operations in Shell Script

I 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
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>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 ?
Avatar of Skytzo
Skytzo


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.