The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: want display a line with space in file by unix script
Hopper
Newbie
Rank: 1



UID 176
Digest Posts 0
Credits 0
Posts 58
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:32 AM  Profile | P.M. 
want display a line with space in file by unix script



want display a line with space in file by unix script



hi ,

i am having a file as

-----------------a.out-------------------
hi i am
unix developer
using hp unix
this is a
test
---------------------------------------

i need to read each line by a unix script of the file and to print in console with the space in the line as

sys1000:root>hi i am
sys1000:root> unix developer
sys1000:root> using hp unix
sys1000:root>this is a
sys1000:root> test

can u please let me know is this possible if so how ? please give the script.

thanks in advance,


Top
Anghus
Newbie
Rank: 1



UID 54
Digest Posts 0
Credits 0
Posts 38
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
is this what you want:

code:

while read iline
do
Top
-Abhishek-
Newbie
Rank: 1



UID 25
Digest Posts 0
Credits 0
Posts 18
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
did you mean reading from the file and displaying it ? there had been so many posts discussing the same.

else,
is your requirement to read from the console and then print the contents.
Top
DomainDomain
Newbie
Rank: 1



UID 120
Digest Posts 0
Credits 0
Posts 48
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
this script doent print the space it simply print the line without space in starting of the line ..

please let me know how to print space line with the space in starting of the line
Top
MD.45
Newbie
Rank: 1



UID 259
Digest Posts 0
Credits 0
Posts 25
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
quote:
this script doent print the space it simply print the line without space in starting of the line ..

please let me know how to print space line with the space in starting of the line




code:
while ifs= read iline
do
Top
forumrating
Newbie
Rank: 1



UID 149
Digest Posts 0
Credits 0
Posts 113
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
try

code:
Top
Michael_Goldman
Newbie
Rank: 1



UID 263
Digest Posts 0
Credits 0
Posts 14
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:33 AM  Profile | P.M. 
i think the main problem is that your original question was not put very well.

you seemd to ask how you can read a file and output it with a space at the begining of each line. this is a rather simple thing to do and can be achieved with any number of tools, 'sed' probably being the simplest:

code:

sed -e 's/^/ /' file.txt
however in your given example you only have an extra space at the begining of lines 2,3 and 5 ... and each line has what looks like your command line prompt at the begining (which doesn't make sense).

please try again to specify exactly what you want, and if possible why.
Top
aznjason
Newbie
Rank: 1



UID 63
Digest Posts 0
Credits 0
Posts 45
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:34 AM  Profile | P.M. 
no i didnt mean that to do ... as an example i want to print the below line as it is

file 1:
==============================
1233333
2222
33333
=======================


the output should be as it but when i tried to do a print by reading the file it is showing as

1233333
2222
Top
darzuaga
Newbie
Rank: 1



UID 106
Digest Posts 0
Credits 0
Posts 50
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:34 AM  Profile | P.M. 
all,

this works fine


sed '2,3s/^/ /;5s/^/ /' input_file

can you please explain the same really tough to understand
Top
deano6410
Newbie
Rank: 1



UID 110
Digest Posts 0
Credits 0
Posts 10
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 13, 2007 10:34 AM  Profile | P.M. 
code:

sed '2,3s/^/ /;5s/^/ /' input_file
2,3 - lines 2 through 3
s - substitute
/ - substitute delimiter (first)
^ - beginning of line
/ - substitute delimiter (middle)
space - change beginning of line to this string
/ - substitute delimiter (end)
; - sed command separator
5 - line 5
s - substitute
/ - substitute delimiter (first)
^ - beginning of line
/ - substitute delimiter (middle)
space - change beginning of line to this string
Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:24 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.006307 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP