General discussion

Locked

Shell script !

By vavazquez652 ·
I'm trying to create an unix script shell for reading a file with this text:

Example:
1 Error log not found!
2 Error on file!
3 Error on permissions!

And this my script shell:

A='cat file'
for in in $A
do
echo $i
done

the information displayed on my screen is this:
1
Error
log
not
found!
2
Error
on
file!
3
Error
on
permissions!

And what I need is the information displayed in the followinf format:
1 Error log not found!
2 Error on file! 3 Error on permissions!

How can I keep it together or just the message in the variable.

Thank you for your help

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Shell script !

by Steve Cody In reply to Shell script !

What shell are you using? This is how you do it in KSH. It may work with other shells as well, and it is probably the same concept. You need to change the Initial Field Separator (IFS) value to a CR/LF, or whatever the ^J is.

This will work for you with ksh.

For the first line below, enter the first ' then press CTRL-J. It will move the cursor to the next line. Then enter the closing '. That will take care of it. You won't actually see a ^J appear on your screen, I don't think. Maybe you will if you are entering it in VI.

export IFS='^J'
A='cat file'
for i in $A
do
echo $i
done

Collapse -

Shell script !

by vavazquez652 In reply to Shell script !

The answer has been great I solved the problem thank you

Collapse -

Shell script !

by vavazquez652 In reply to Shell script !

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums