shell replacing space with line breaks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell replacing space with line breaks
# 1  
Old 04-21-2009
Error shell replacing space with line breaks

I'm parsing through a large lslpp -Lc output file with a for loop. The file contains many lines similar to this:
zip:zip-2.3-3:2.3: : :C:R:A file compression and packaging utility compatible with PKZIP.: :/bin/rpm -e zip: : : : :0:

There appears to be no specialized or secret markup in the file.
However, when I try reading through the file in a loop while in a shell script, it breaks up every space as a line break, and each line break as a double break.
Below is the code:
Code:
#!/usr/bin/ksh
for i in `cat -n servername.lpp`
do 
echo "$i"
done

The strange thing is that cat does not seem to notice that the lines are being broken up, as indicated by the output below.
I also tried reading in the file with a second perl script (for i in `perl perlscript.pl) and got exactly the same problem.

Output from entering the

Output from script file:
Code:
 1
#Package
Name:Fileset:Level:State:PTF
Id:Fix
State:Type:Description:Destination
Dir.:Uninstaller:Message
Catalog:Message
Set:Message
Number:Parent:Automatic:EFIX
Locked:Install
Path:Build
Date
2
Java14.sdk:Java14.sdk:1.4.2.175:
:
:C:F:Java
SDK
32-bit:
:
:
:
:
:
:0:0:/:


I've also tried this with bash shell specified. I'm not sure how to resolve this. Any help would be appreciated.

Last edited by mshulman1980; 04-21-2009 at 02:38 PM.. Reason: Replaced quote tag with code tag to avoid auto emoticon insertion
# 2  
Old 04-21-2009
please provide a sample input and expected output file


cheers,
Devaraj Takhellambam
# 3  
Old 04-21-2009
Sample input:
[CODE]
readline:readline-4.3-2:4.3: : :C:R:A library for reading and returning lines from a terminal.: :/bin/rpm -e readline: : : : :0:
sudo:sudo-1.6.7p5-3:1.6.7p5: : :C:R:Allows restricted root access for specified users.: :/bin/rpm -e sudo: : : : :0:
unzip:unzip-5.51-1:5.51: : :C:R:A utility for unpacking zip files.: :/bin/rpm -e unzip: : : : :0:
wget:wget-1.9.1-1:1.9.1: : :C:R:A utility for retrieving files using the HTTP or FTP protocols.: :/bin/rpm -e wget: : : : :0:
zip:zip-2.3-3:2.3: : :C:R:A file compression and packaging utility compatible with PKZIP.: :/bin/rpm -e zip: : : : :0:

[ /CODE]

the output should be identical. Once I'm able to load each line into memory, I will parse through the lines.
# 4  
Old 04-21-2009
I'd use a while loop...for example:

IFS=":"
while read line; do
echo $line
done <servername.lpp
# 5  
Old 04-21-2009
try using a while loop instead...your issue seems to be because of the echo command

while read line
do
echo $line
done < "filename"

if you want the line number also:

i=1;while read line; do echo "$i $line";i=`expr $i + 1`; done < "filename"


cheers,
Devaraj Takhellambam
# 6  
Old 04-21-2009
giannicello: thanks!

I appended the script to add the colons back in for later parsing.

#!/bin/bash
IFS=":"
while read line; do
echo $line
done <servername.lpp|tr ' ' ':'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] read 'line' issue with leading tabs and virtual line breaks

Heyas I'm trying to read/display a file its content and put borders around it (tui-cat / tui-cat -t(ypwriter). The typewriter-part is a 'bonus' but still has its own flaws, but thats for later. So in some way, i'm trying to rewrite cat using bash and other commands. But sadly it fails on... (2 Replies)
Discussion started by: sea
2 Replies

2. HP-UX

After using @, line breaks for a particular user in shell

Dear Concern, When we using @ sign, line breaks for a particular user in shell. Please advise how to resolve from the problem in HP UX. tabs@tabsdb02:/ccbs/users/tabs$ cat /etc/passwd|grep tabs tabs:RdCgOsmKee7Ps:221:201::/ccbs/users/tabs:/usr/bin/ksh... (3 Replies)
Discussion started by: makauser
3 Replies

3. UNIX for Dummies Questions & Answers

Page breaks and line breaks

Hi All, Need an urgent solution to an issue . We have created a ksh file or shell script which generates 1 DAT file. the DAT file contains extract of a select statement . Now the issue is , when we are executing the ksh file , the output is coimng with page breaks and line breaks . We have... (4 Replies)
Discussion started by: Ayaskant
4 Replies

4. Shell Programming and Scripting

my shell now adds extra space at end of each line!

Hi, Since today, with csh or tcsh, if I do 'ls files* > list', every lines end with an extra space! What happenned? What can I do to go back when there was no extra space? If I change to bash, there's no extra space. Thanks, Patrick ---------- Post updated at 03:19 PM... (1 Reply)
Discussion started by: trogne
1 Replies

5. Programming

Clean and keep line breaks

Hello, I want to keep line spaces in comments but clean more then 2 after each. Example: $sentence="This is my first sentence This will be in a new row This will be too in a new row but not separated with 3line breaks just with one "; And i want to... (1 Reply)
Discussion started by: AimyThomas
1 Replies

6. Shell Programming and Scripting

Remove line breaks in csv file using shell script

Hi All, I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double... (4 Replies)
Discussion started by: rajak.net
4 Replies

7. Shell Programming and Scripting

Replacing space with T only in the 1st line of the file

Hi Masters , I have a file whose header is like HDRCZECM8CZCM000000881 SVR00120100401160828+020020100401160828+0200CZK There is a space between 1 and S ,my req is to chng the space to T I tried echo `head -1 CDCZECM8CZCM000000881` | sed 's/ /T/' it works ,but how can I modify in... (5 Replies)
Discussion started by: Pratik4891
5 Replies

8. Shell Programming and Scripting

Help with wc and line breaks

Hi everyone, I have gone through the forum trying to find an answer to this question but was unsuccessful. I am hoping that someone can help me with this please. I am trying to get my script to recognise line breaks from a file and to give me a result for wc of each line. So basically, if you... (7 Replies)
Discussion started by: stargazerr
7 Replies

9. Shell Programming and Scripting

any better way to remove line breaks

Hi, I got some log files which print the whole xml message in separate lines: e.g. 2008-10-01 14:21:44,561 INFO do something 2008-10-01 14:21:44,561 INFO print xml : <?xml version="1.0" encoding="UTF-8"?> <a> <b>my data</b> </a> 2008-10-01 14:21:44,563 INFO do something again I want... (3 Replies)
Discussion started by: csmklee
3 Replies

10. Shell Programming and Scripting

Removing line breaks from a shell variable

Here is my snippet of code... getDescription() { DESCRIPTION=$(dbaccess dncsdb - << ! 2>/dev/null|sed -e 's/hctt_description//' -e '/^$/ d'|tr -d '\r' select hct_type.hctt_description from hct_type,hct_profile where hct_type.hctt_id=hct_profile.hctt_id and... (5 Replies)
Discussion started by: lyonsd
5 Replies
Login or Register to Ask a Question