0

I've got a load of files containing preamble rubbish followed by formatted information. They're all the same format. I want to ignore the preamble, (everything up to and including the word "Description"), and sort the remaining, (everything from, and including the word "Chassis"), into .csv files. Example: BEFORE:
random blah
random blahrandom x blahrandom blah
randomblah xx randomblah
random xxxx blah
sss
Hardware inventory:
Item_____________Version__Part number__Serial number_____Description
Chassis______________________________JN110XXX3AFA___MXX60
Midplane_________REV 03__710-013698__TXXX93__________MXX60 Backplane
FPM Board_______REV 03__710-014974__XA8XXX__________Front Panel Display
PDM____________Rev 03___740-013110__QCXXX19500H____Power Distribution Module
PEM 0___________Rev 04___740-013682_QCXXX43409S_____PS 170kW; 200-240VAC in

AFTER:
Chassis,,,JN110XXX3AFA,MXX60
Midplane,REV 03,710-013698,TXXX93,MXX60 Backplane
FPM Board,REV 03,710-014974,XA8XXX,Front Panel Display
PDM,Rev 03,740-013110,QCXXX19500H,Power Distribution Module
PEM 0,Rev 04,740-013682,QCXXX43409S,PS 170kW; 200-240VAC in

I've been working on reading it in one word at a time and searching for the trigger word to "Description" change to conversion into .csv but I wanted to know if I'm going about it the right/best way please? (Sorry about the lousy formatting above - all the originals are in nice neat columns).

Thanks

Andy.

3
  • Please take the time to learn how to format your question. It was a mess. I've tidied it for you.
    – Dave
    May 14, 2014 at 13:46
  • Sorry Dave I did try quite hard to restore the fixed space formatting that it started out as. May 14, 2014 at 14:03
  • No worries, it does take a while to get used to :)
    – Dave
    May 14, 2014 at 14:04

1 Answer 1

0

To delete up to and including the header line:

sed -e '1,/^Hardware inventory:$/d' my_file

This does not change the file itself, but rather prints the part of the file after the Hardware inventory: line. To change the file itself you'll need to add -i to the options.

man sed has much more information.

5
  • I've copied and pasted this, and followed it with the source and destination filenames but it doesn't change the file? I'd expect it to delete all the entries up "Item", or am I misunderstanding its use? May 14, 2014 at 15:05
  • I've found it works if I omit the search string enclosures ^ and $ 'sed '1,/Hardware inventory:/d' $DIR/$HOST > testdone' May 15, 2014 at 8:18
  • Adapted for other uses too now. Thanks for the help over the initial sed knowledge. May 15, 2014 at 8:45
  • Having continuing problems with sed. This above 'sed -e '1,/^Hardware inventory:$/d' my_file' didn't work, and neither does 'sed -e '/^ *$/d' $DIR/temp2 > $DIR/temp3' to delete blank lines. May 15, 2014 at 13:57
  • AHA!!! But this does > sed '/^\x0D\?$/d' myFile > output Obviously my file didn't just have a ^M to get rid of. Thanks anyway. :-) May 15, 2014 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .