![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 08:44 PM |
| Removing line breaks from a shell variable | lyonsd | Shell Programming and Scripting | 5 | 09-12-2006 02:42 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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. |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|