Need help on Concatenating consecutive lines 
Author Message
 Need help on Concatenating consecutive lines

Hi,

I need your help in manipulating a file using awk or sed . The
original file looks like this

Table: 'PS_INS_EDY_TER'
- Scan Density 100.00% [39:39]
Table: 'PS_PO_DFLT_TBL'
- Scan Density 100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A'
- Scan Density 90.00% [15:15]

I need to concatenate line that starts with string "Table" with the
NEXT line that starts with "- Scan"  As seen below

Table: 'PS_INS_EDY_TER' - Scan Density  100.00% [39:39]
Table: 'PS_PO_DFLT_TBL' - Scan Density  100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

And then check the value of scan density i.e. 100.00%,100.00%,90.00%
as shown
above and display lines that will have less than 95.00% density. hence
final output will be

Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

I would greatly appreciate your help in solving this problem.

Thanks in Advance,

Regards,

Rahul Bakare



Sat, 06 Dec 2003 03:47:05 GMT  
 Need help on Concatenating consecutive lines

Quote:

> Hi,

> I need your help in manipulating a file using awk or sed . The
> original file looks like this

> Table: 'PS_INS_EDY_TER'
> - Scan Density 100.00% [39:39]
> Table: 'PS_PO_DFLT_TBL'
> - Scan Density 100.00% [15:15]
> Table: 'PS_EX_SHT_HDR_A'
> - Scan Density 90.00% [15:15]

> I need to concatenate line that starts with string "Table" with the
> NEXT line that starts with "- Scan"  As seen below

> Table: 'PS_INS_EDY_TER' - Scan Density  100.00% [39:39]
> Table: 'PS_PO_DFLT_TBL' - Scan Density  100.00% [15:15]
> Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

> And then check the value of scan density i.e. 100.00%,100.00%,90.00%
> as shown
> above and display lines that will have less than 95.00% density. hence
> final output will be

> Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

> I would greatly appreciate your help in solving this problem.

> Thanks in Advance,

> Regards,

> Rahul Bakare

Using gawk:
awk '{if((getline tmp)>0){$0=$0tmp}{if(int($6)<95)print $0}}' infile

There may be some things left to check for you, however it works with
the data
you provided.

Good luck

Michael Heiming



Sat, 06 Dec 2003 04:31:28 GMT  
 Need help on Concatenating consecutive lines

Quote:

>Hi,

>I need your help in manipulating a file using awk or sed . The
>original file looks like this

>Table: 'PS_INS_EDY_TER'
>- Scan Density 100.00% [39:39]
>Table: 'PS_PO_DFLT_TBL'
>- Scan Density 100.00% [15:15]
>Table: 'PS_EX_SHT_HDR_A'
>- Scan Density 90.00% [15:15]

>I need to concatenate line that starts with string "Table" with the
>NEXT line that starts with "- Scan"  As seen below

>Table: 'PS_INS_EDY_TER' - Scan Density  100.00% [39:39]
>Table: 'PS_PO_DFLT_TBL' - Scan Density  100.00% [15:15]
>Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

>And then check the value of scan density i.e. 100.00%,100.00%,90.00%
>as shown
>above and display lines that will have less than 95.00% density. hence
>final output will be

>Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

Doing it all at once:

awk '/^Table:/ {a=$0}
     /^- Scan/ {b=$4; sub(/%/,"",b); if(b<95.00){print a, $0}}' infile

This is untested, but should work.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sat, 06 Dec 2003 05:40:49 GMT  
 Need help on Concatenating consecutive lines
Hi.  Can either of you post a more generic solution that would
concatenate, say, every 5th or 8th or nth line in a given file
regardless ot the text in each line?  I'm sure I've seen it here
before but am unable to find it.

thia,
tony



Quote:


>>Hi,

>>I need your help in manipulating a file using awk or sed . The
>>original file looks like this

>>Table: 'PS_INS_EDY_TER'
>>- Scan Density 100.00% [39:39]
>>Table: 'PS_PO_DFLT_TBL'
>>- Scan Density 100.00% [15:15]
>>Table: 'PS_EX_SHT_HDR_A'
>>- Scan Density 90.00% [15:15]

>>I need to concatenate line that starts with string "Table" with the
>>NEXT line that starts with "- Scan"  As seen below

>>Table: 'PS_INS_EDY_TER' - Scan Density  100.00% [39:39]
>>Table: 'PS_PO_DFLT_TBL' - Scan Density  100.00% [15:15]
>>Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

>>And then check the value of scan density i.e. 100.00%,100.00%,90.00%
>>as shown
>>above and display lines that will have less than 95.00% density. hence
>>final output will be

>>Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]

>Doing it all at once:

>awk '/^Table:/ {a=$0}
>     /^- Scan/ {b=$4; sub(/%/,"",b); if(b<95.00){print a, $0}}' infile

>This is untested, but should work.

>Chuck Demas

>--
>  Eat Healthy    |   _ _   | Nothing would be done at all,

>  Die Anyway     |    v    | That no one could find fault with it.




Sun, 07 Dec 2003 02:53:56 GMT  
 Need help on Concatenating consecutive lines
Quote:

>Hi.  Can either of you post a more generic solution that would
>concatenate, say, every 5th or 8th or nth line in a given file
>regardless ot the text in each line?  I'm sure I've seen it here
>before but am unable to find it.

...

What do you mean 'concatenate every 5th line'? Concatenate those line with
what? The previous line? Concatenate every 5 lines?

If concatenating lines 4 and 5, 9 and 10, 14 and 15, etc.,

{ n = 5 - (5 - NR) % 5; if (n < 4) print; else if (n == 4) s = $0; else
print s $0 }

If concatenating every group of 5 lines,

{ s = s $0 } NR % 5 == 0 { print s; s = "" }



Sun, 07 Dec 2003 03:32:42 GMT  
 Need help on Concatenating consecutive lines


Quote:
>What do you mean 'concatenate every 5th line'? Concatenate those line with
>what? The previous line? Concatenate every 5 lines?

>If concatenating lines 4 and 5, 9 and 10, 14 and 15, etc.,

>{ n = 5 - (5 - NR) % 5; if (n < 4) print; else if (n == 4) s = $0; else
>print s $0 }

>If concatenating every group of 5 lines,

>{ s = s $0 } NR % 5 == 0 { print s; s = "" }

Sorry...I did mean concatenating every group of 5 lines.  Your
solution works graet.

thanks



Sun, 07 Dec 2003 22:38:30 GMT  
 Need help on Concatenating consecutive lines
infile:
Table: 'PS_INS_EDY_TER'
- Scan Density 100.00% [39:39]
Table: 'PS_PO_DFLT_TBL'
- Scan Density 100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A'
- Scan Density 90.00% [15:15]

awk '{ if($1~/-/)printf "%s\n",$0;else printf "%s",$0 }' infile

outfile:
Table: 'PS_INS_EDY_TER' - Scan Density 100.00% [39:39]
Table: 'PS_PO_DFLT_TBL' - Scan Density 100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]



Mon, 08 Dec 2003 04:21:26 GMT  
 Need help on Concatenating consecutive lines
infile:
Table: 'PS_INS_EDY_TER'
- Scan Density 100.00% [39:39]
Table: 'PS_PO_DFLT_TBL'
- Scan Density 100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A'
- Scan Density 90.00% [15:15]

awk '{ if($1~/-/)printf "%s\n",$0;else printf "%s",$0 }' infile

output reslt:
Table: 'PS_INS_EDY_TER' - Scan Density 100.00% [39:39]
Table: 'PS_PO_DFLT_TBL' - Scan Density 100.00% [15:15]
Table: 'PS_EX_SHT_HDR_A' - Scan Density 90.00% [15:15]



Mon, 08 Dec 2003 04:24:23 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. portably compacting consecutive blank lines..

2. Number of consecutive comment lines in Fortran

3. Please help me to concatenate data files

4. Help needed - how to remove some lines

5. Need help : extracting a line of a file

6. Newbie needing help to print previous lines...

7. ******How to make a line..I need help

8. Need help to access command line in device driver

9. NEED HELP DRAWING LINES DIRECTLY!

10. Need help with balance line algorithm.

11. Need HELP on finishing pics on next line.

12. Student needs help with printing blank line....

 

 
Powered by phpBB® Forum Software