General discussion

Locked

Unix script to select information.

By vavazquez652 ·
I need help to create file for reading and process information in a file:

File Content:

962113897 B 10/1/04 12/31/04 100%
962113897 O 10/1/04 12/31/04 100%
962115794 B 10/1/04 12/31/04 100%
962115794 O 10/1/04 12/31/04 100%


Fisrt Case:
If the second field contain a "B" I need to repeat the all the registry in the following order and adding a new field containing the following letters G,K,E,O,W,T,U,V on the second column and redirect the result to a file.

Example:

962113897|G|B|100%|10/1/04|12/31/04|
962113897|K|B|100%|10/1/04|12/31/04|
962113897|E|B|100%|10/1/04|12/31/04|
962113897|O|B|100%|10/1/04|12/31/04|
962113897|W|B|100%|10/1/04|12/31/04|
962113897|T|B|100%|10/1/04|12/31/04|
962113897|U|B|100%|10/1/04|12/31/04|
962113897|V|B|100%|10/1/04|12/31/04|


Second Case:

If the second field contain a "O" I need to repeat the all the registry in the following order and adding a new field containing the following letters B,A,D,P,H, on the second column and redirect the result to a file.

Example:

962113897|B|O|100%|10/1/04|12/31/04|
962113897|A|O|100%|10/1/04|12/31/04|
962113897|D|O|100%|10/1/04|12/31/04|
962113897|P|O|100%|10/1/04|12/31/04|
962113897|H|O|100%|10/1/04|12/31/04|

The total result must be like this:

962113897|G|B|100%|10/1/04|12/31/04|
962113897|K|B|100%|10/1/04|12/31/04|
962113897|E|B|100%|10/1/04|12/31/04|
962113897|O|B|100%|10/1/04|12/31/04|
962113897|W|B|100%|10/1/04|12/31/04|
962113897|T|B|100%|10/1/04|12/31/04|
962113897|U|B|100%|10/1/04|12/31/04|
962113897|V|B|100%|10/1/04|12/31/04|
962113897|B|O|100%|10/1/04|12/31/04|
962113897|A|O|100%|10/1/04|12/31/04|
962113897|D|O|100%|10/1/04|12/31/04|
962113897|P|O|100%|10/1/04|12/31/04|
962113897|H|O|100%|10/1/04|12/31/04|

Thank You for your help !

Best Regards !

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Gary_W In reply to Unix script to select inf ...

There's probably a trickier way to do it, but this example should be easy to follow. Create process.sh below and call lihe this:
process.sh <sourcefile>. Output will go to <sourcefile>.out. Note that there should be error handling added, etc.

Gary

=== process.sh ===
outfile=$1.out
> $outfile
cat $1 | while read line
do
set $line
if [ $2 = 'B' ]
then for i in G K E O W T U V
do
echo "$1|$i|$2|$5|$3|$4|" >> $outfile
done
else if [ $2 = 'O' ]
then for i in B A D P H
do
echo "$1|$i|$2|$5|$3|$4|" >> $outfile
done
fi
fi
done
echo "Output in $outfile"
==== End process.sh ====

Collapse -

by vavazquez652 In reply to

It worked as we wished !

Thank You !

Best Regars

Collapse -

by vavazquez652 In reply to Unix script to select inf ...

This question was closed by the author

Back to Linux Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums