The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replacing space with pipe(delimiter) OSD UNIX for Dummies Questions & Answers 6 02-16-2009 04:38 AM
any better way to remove line breaks csmklee Shell Programming and Scripting 3 01-13-2009 02:42 AM
Replacing URL in a file with space dsrookie UNIX for Dummies Questions & Answers 5 02-29-2008 04:58 AM
Newbie ? Need Help with If/Then & Line Breaks... kthatch UNIX for Dummies Questions & Answers 1 05-01-2007 07:44 PM
Removing line breaks from a shell variable lyonsd Shell Programming and Scripting 5 09-12-2006 01:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2009
mshulman1980 mshulman1980 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 4
Exclamation 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 01:38 PM.. Reason: Replaced quote tag with code tag to avoid auto emoticon insertion
  #2 (permalink)  
Old 04-21-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
please provide a sample input and expected output file


cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 04-21-2009
mshulman1980 mshulman1980 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 4
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 (permalink)  
Old 04-21-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Location: Phoenix
Posts: 169
I'd use a while loop...for example:

IFS=":"
while read line; do
echo $line
done <servername.lpp
  #5 (permalink)  
Old 04-21-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
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 (permalink)  
Old 04-21-2009
mshulman1980 mshulman1980 is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 4
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 ' ' ':'
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0