2

I have a file with data as below

enter image description here I want to extract the lines and write to another files. The o/p should be

enter image description here I want to do this in a unix shell script.

  • Get everything between lines 100 and 123: sed -n '100,123p' datafile – roblogic Oct 8 '15 at 5:38
  • 1
    Get rid of the tags: sed -n 's/<start>//gp;s/<end>//gp', you might need to escape the <> characters with a backslash `\` – roblogic Oct 8 '15 at 5:47
  • 1
    Please do not post images of text. Copy & paste the text itself, putting it into a code block to preserve formatting. – PM 2Ring Oct 8 '15 at 8:13
2

Your example data can be almost transformed as requested like:

sed 's/<[^>]*>//g' <infile >outfile

There is that last trailing | pipe thing on the line6 line. Because your example is apparently a screen shot I'm thinking it is actually your cursor in freeze-frame.

I'm uncertain if it is a mistake or if it is meant to represent an outlier, but, either way, this doesn't handle it. I could make it so, but I would need some clarification on that score.

However, if that's as difficult as it gets, then it will work.

1
sed 's/.*\(line[0-9]*\).*/\1/' file > new_file

Input

<start>line1<end>
line2
line3<end>
<start>line4
line123
<start>line12<>
<>line<end>
<start>line456

Output

line1
line2
line3
line4
line123
line12
line
line456

It will extract for your any line[digit] from any string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.