i want to create a shell script that divide a text file to parts and take the information from each part and store it

i want to create a shell script

good for you

divide a text file to parts

based on what?

take the information from each part and store it

where?

show input, and desired output!

hi
thank you for replay
i have the following text file

seg{
            ax 3100,
           as 2,
           az 112,
            aq 1,
            },
        seg { 
            ax 3100,
            as 2,
            az 137,
          aq 4,

        },
     seg { 
          ax 3100,
            as 2,
            az 22,
            aq 8,
            },



        now i want to divide the text file to parts such that each part contain a seg block
         seg { 
        ax 3100,
        as 2,
        az 137,
      aq 4,
       },
    and from each seg construct the following
    ax.as.az.aq
    to become the following 
    3100.2.137.4
    co how can i do this in shell script?????

i want to divide the text file to parts

I suppose you mean break the main file into smaller files containing only one seg part each.

how can i do this in shell script?????

as you're working on interval (between seg{ and },) it'd be easy to use sed,
but I don't know how to generate file names from within.
so, I suggest you use awk.
not every awk does work on interval as easily as sed, even it's a bit tedious, it's not difficult to say: if line is "seg{", then process begins, else if line is "},", then process ends, endfi (more or less).

Edit:
you could also split the main file into 6 lines files, and transform each using sed.

Edited 4 Years Ago by Watael

thank you for replay i donot want to put each segment in a file because my text file contain 60 seg so it will be a lot of files cannot i process what i want without using files and you explain more about the commands because i am new to shell script

it's your homework, you have to build an algorithm, and use the language you've been taught, so you learn!

Show what you've done.
Tell where your stuck,
then we'll be glad to help.

This article has been dead for over six months. Start a new discussion instead.