Quote:
#!/bin/sh
# Read until line complete. Anything after the first line is part of field 4 - Assignment
cat hotroddata | awk '
$1 !~ /DEVCONFIG/ { if ((fourzerotwo=="") && (fourzeroone==""))
fourzeroone = $0
if ((fourzeroone!="") && (fourzerotwo==""))
fourzerotwo = $0 }
$1 ~ /DEVCONFIG/ { print prime, fourzero fourzeroone fourzerotwo;
fourzero=fourzeroone=fourzerotwo="";
prime = ($1 " " $2 " " $3);
fourzero = $4 " " $5 " " $6 " " $7 " " $8 " " $9 }
END { if ((fourzerotwo != "") || (fourzeroone != ""))
print prime, fourzero fourzeroone fourzerotwo; }
' | less ## > output file
## I'm sure you will know what to do with the last line when you have it licked.
|
~
I regret that it is late in the UK and I have to be up in the morning so my solution is only partial due to lack of time on my part.
I copied your input data by cutting and pasting it and called it "hotroddata". So we can see your input data from your post and here is my output data which falls far short of your mark - at the moment.
DEVCONFIG*143 143 INCOMING3 lpr -P INCOM ING3ING3
DEVCONFIG*144 144 PACKHP rsh ps22 11
DEVCONFIG*145 145 CT.SET3 lpr -P SETS3
DEVCONFIG*146 146 PACKHP.2 rsh ps21 9
DEVCONFIG*147 147 MOLDHP rsh ps6 7
DEVCONFIG*148 148 SHIP5 rsh ps1 8
DEVCONFIG*149 149 PACKHP.1 rsh ps6 8
DEVCONFIG*150 150 MEC2 rsh ps1 11
DEVCONFIG*151 151 CT.SET4 lpr -P SETS4
DEVCONFIG*152 152 PRINTRONIX1 rsh ps1 13
DEVCONFIG*153 153 SHIP1 rsh ps1 14 ^[[H^[[2J
DEVCONFIG*154 154 RMHP rsh ps16 9
DEVCONFIG*155 155 PBINV cat >/data/p ublic/pbinvoublic/pbinvo
DEVCONFIG*156 156 CT.SET5 lpr -P SETS5
DEVCONFIG*157 157 SETHP rsh ps25 16
DEVCONFIG*158 158 PEGHP rsh ps5 13
DEVCONFIG*159 159 POLYEHP rsh ps6 2
DEVCONFIG*160 160 EMAIL /data/script s/email.pls/email.pl
DEVCONFIG*161 161 PACKZB.4 lpr -P PACKZ B.4B.4
DEVCONFIG*162 162 HR rsh ps13 2
DEVCONFIG*163 163 ARHP rsh ps10 4
DEVCONFIG*164 164 ARVHP lpr -P ARVHP
DEVCONFIG*165 165 ARHP.5 rsh ps13 8
DEVCONFIG*166 166 ITADMIN lpr -P IT_AD MINMIN
On the basis that all lines began with DEVCONFIG and that I was likely to have an uncommitted print at the end I proceeded.
Question: did you want the first line of your data to actually look like this:
DEVCONFIG*143143INCOMING3 lpr -P INCOMING3ING3
This is what I think Mathew was confused about, and I had missed, the first three columns want concatenated without white space?
if that's correct, then removing the spaces in the assignment to "prime" should fix that no bother.
I took a blunt instrument approach to ensuring that elements of column 4 (5, 6 ,7, 8 etc) didn't lose their proper spaces. This of course caused a bit of a problem in that it put spaces where the data was originally broken over lines.
The multiple spaces I didn't see as a problem as I would just pipe the output through tr to single-up multiple spaces. The space prior to the broken line (see AD MINMIN [Woops that extra MIN came from sloppy thinking in the END tag] I would get rid of by writing an awk function to process things slightly more elegantly.
The control sequences ^[[H^[[2J I would get rid of in my function by discarding any ^ character and anything to the right of it.
I would imagine you will be well fixed by the time I get to have a look in again tomorrow evening. Good luck. A shame my sed is dusty (I think sed would have been more appropriate for sorting the lines) and my awk is a couple of years off speed and in need of exercising.
How to preserve indentation of code in this editor without compromising it?
PAix