The UNIX and Linux Forums  


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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-22-2007
sabyasm sabyasm is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 27
Post deleting particular lines and moving a line up using perl/sed

Hi,

I need convert a dump file in the following format : (please note that line numbers are provided for easy look)

Original file:

1 2007-10-2482.90 No trade 0 0.00 100000.00
2 100000.00
3 0.00
4 HOLD
5 2007-10-2589.75 Bought 1114 1114 100000.00 0.00
6 100000.00
7 -0.00
8 STRONG BUY
9 2007-10-2692.35 No trade 1114 102896.94 0.00
10 102896.94
11 2.90
12 STRONG BUY
13 2007-10-2991.20 No trade 1114 101615.60 0.00
14 101615.60
15 1.62
16 STRONG BUY
17 2007-10-3090.05 No trade 1114 100334.26 0.00
18 100334.26
19 0.33
20 STRONG BUY
21 2007-10-3188.45 No trade 1114 98551.53 0.00
22 98551.53
23 -1.45
24 STRONG BUY
25 2007-11-0183.70 Sold 1114 0 0.00 93259.05
26 93259.05
27 -6.74
28 STRONG SELL

Modifiled file :

1 2007-10-2482.90 No trade 0 0.00 100000.00 HOLD
2 2007-10-2589.75 Bought 1114 1114 100000.00 0.00 STRONG BUY
3 2007-10-2692.35 No trade 1114 102896.94 0.00 STRONG BUY
4 2007-10-2991.20 No trade 1114 101615.60 0.00 STRONG BUY
5 2007-10-3090.05 No trade 1114 100334.26 0.00 STRONG BUY
6 2007-10-3188.45 No trade 1114 98551.53 0.00 STRONG BUY
7 2007-11-0183.70 Sold 1114 0 0.00 93259.05 STRONG SELL


That is, every 4 line of the input file needs to converted into a single line - after deleting 2nd and 3rd line.

A perl script to do this would be great. (sed will also fulfill my purpose but perl way will be highly appreciated).

Awaiting for your help!