2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Watael
0

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!

0

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?????
0

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 by Watael

0

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.