03-19-06 05:02 PM
Le Sat, 18 Mar 2006 07:38:32 -0800, pankaj_wolfhunter a écrit_:
> Greetings,
>
> I have a file as:
>
> name1|value1|value2|N
> name1|value3|value4|N
> name1|value5|value6|N
> name1|value7|value8|Y
> name2|value1|value2|N
> name2|value3|value4|N
> name2|value5|value6|Y
> .....................
> .....................
>
> I want to start looping the file and for each name(name1, name2) and
> for each name
> I want to check the value in 4 column.
> If the column value is N then I want to move to the next line for the
> same
> name. Whenever I find the fourth column value as Y, I want to put
> only 2nd and 3rd column value for this name into one line along with
> its name.
>
> Req Output
>
> name1|value1|value2|value3|value4|value5
|value6|value7|value8
> name2|value1|value2|value3|value4|value5
|value6.
>
> The prob here is, In between a name, a second name may appear.
> like
> name1|value1|value2|N
> name3|value1|value2|N
> name1|value3|value4|N
> name1|value5|value6|Y
>
> So if the script starts with one name then it should go on with that
> name
> until the fourth column value becomes Y and then for the second name
> and so on.
>
> Can someone please help me build with this logic or some script
> which would guide me in right direction.
>
> Any help would be appreciated
>
> TIA
Apart the good awk solution Janis Papanagnou posted which I would
use in your case, but as you didn't post what exactly was the process
you used, I just wondered if sorting your file before processing it
thru your filter wouldn't be just what you'd want ?
As your 'triggers' are on sorted names and "N" then "Y"
it's already a sorted index, then given your sample :
$ cat MISCFILES/sorteed.txt
name1|value1|value2|N
name3|value1|value2|N
name1|value3|value4|N
name1|value5|value6|N
name1|value7|value8|Y
name2|value1|value2|N
name2|value3|value4|N
name2|value5|value6|Y
Using this would bring you in good shape for your filtering ?
$ sort MISCFILES/sorteed.txt
name1|value1|value2|N
name1|value3|value4|N
name1|value5|value6|N
name1|value7|value8|Y
name2|value1|value2|N
name2|value3|value4|N
name2|value5|value6|Y
name3|value1|value2|N
Please, if this is wrong, comment and give sample for
failure of this, as I'm not sure I've understood all what
you wanted to nor what you already had !?-D)
[ Post a follow-up to this message ]
|