Hi there I'am new here and could use some help. I probably haven't used the correct terms but have tried my best.
I work for a newspaper who run a database for their classifieds.
All the adds are input on an atex system and then each day dumped into three files. (*.eps *.srt *.prn)
I'am trying my best to work out how I can change the contents of the sort file (*.srt) to suit our pagination software.
I've been reading as much as possible on sed, awk and grep but feel that with my limited knowledge of scripting I need some help for one of you experts.
The sort file is setout as below
(*.srt)
field 1 field 2 field 3 field 4 field 5
AY53RH00300 01PUN 00022 0002233 33399
DY5DKRR0300 02PUN 00022 000233 33399
AY5344GT300 01FAM 00022 0002233 33399
AY53HJ70300 01FAM 00022 000233 33399
DY5773GG300 02FAM 00022 0002233 33399
AY5MJUYTT00 01FAM 0022 0002233 33399
AY5855GG300 01FAM 00022 0002233 33399
DY53RBDDE00 02FAM 0022 0002233 33399
AY5CDEEE300 01FAM 00022 0002233 33399
DY504333D00 02FOS 0022 0002233 33399
AY5TEGGY700 01FOS 00022 0002233 33399
AY5SEG79O00 01FOS 00022 002233 33399
AY523EDD300 01FOS 00022 0002233 33399
DY356HBN300 02FOS 00022 0002233 33399
AY47IIJG300 01FOS 0022 0002233 33399
AY087F40300 01FOS 00022 0002233 33399
DYVFREDVG00 02FOS 00022 0002233 33399
AY3FGTYH300 01FOS 00022 0002233 33399
AYMKYRFDD00 01TEL 00022 0002233 33399
DYR44RFG300 02TEL 00022 0002233 33399
AY8FBBGFF00 01TEL 0002 0002233 33399
AY53RH00300 01TEL 00022 0002233 33399
DY53RH00300 02TEL 00022 000233 33399
DY53RH00300 02TEL 00022 0002233 33399
DY53RH00300 02PUN 0022 0002233 33399
DY53RH00300 03PUN 00022 0002233 33399
DY53RH00300 02PUN 00022 0002233 33399
DY53RH00300 04PUN 0022 0002233 33399
AY53RH00300 01PUN 00022 0033 33399
AY53RH00300 01PUN 00022 0002233 33399
AY53RH00300 01PUN 00022 00233 33399
first field (FIRST CHARACTER IS EITHER AN A(line ad) OR D(display ad)) (SECOND CHARACTER ALWAY Y (not sure)) (NEXT NINE CHARACTER ARE THE BOOKING NUMBER ALPHANUMERIC This is unique on entry)
Second field (FIRST TWO CHARACTERS 01-08 column width of advert) (THIRD TO FIFTH CHARACTER Classification (eg PUN Public Notice, FOS For Sale)
All other fields remain the same. What I need to do is search for all the 01PUN and 01FAM fields and change them to 02PUN and 02FAM and also change just the first character in field 1 from and A to a D but the booking number stays.
field 1 field 2 field 3 field 4 field 5
DY53RH00300 02PUN 00022 0002233 33399
DY5DKRR0300 02PUN 00022 000233 33399
DY5344GT300 02FAM 00022 0002233 33399
DY53HJ70300 02FAM 00022 000233 33399
DY5773GG300 02FAM 00022 0002233 33399
DY5MJUYTT00 02FAM 0022 0002233 33399
DY5855GG300 02FAM 00022 0002233 33399
DY53RBDDE00 02FAM 0022 0002233 33399
DY5CDEEE300 02FAM 00022 0002233 33399
DY504333D00 02FOS 0022 0002233 33399
AY5TEGGY700 01FOS 00022 0002233 33399
AY5SEG79O00 01FOS 00022 002233 33399
AY523EDD300 01FOS 00022 0002233 33399
DY356HBN300 02FOS 00022 0002233 33399
AY47IIJG300 01FOS 0022 0002233 33399
AY087F40300 01FOS 00022 0002233 33399
DYVFREDVG00 02FOS 00022 0002233 33399
AY3FGTYH300 01FOS 00022 0002233 33399
AYMKYRFDD00 01TEL 00022 0002233 33399
DYR44RFG300 02TEL 00022 0002233 33399
AY8FBBGFF00 01TEL 0002 0002233 33399
AY53RH00300 01TEL 00022 0002233 33399
DY53RH00300 02TEL 00022 000233 33399
DY53RH00300 02TEL 00022 0002233 33399
DY53RH00300 02PUN 0022 0002233 33399
DY53RH00300 03PUN 00022 0002233 33399
DY53RH00300 02PUN 00022 0002233 33399
DY53RH00300 04PUN 0022 0002233 33399
DY53RH00300 02PUN 00022 0033 33399
DY53RH00300 02PUN 00022 0002233 33399
DY53RH00300 02PUN 00022 00233 33399
After some reading I am taking a punt at something below to change field two
sed -e 's/01PUN/02PUN/g' -e 's/01FAM/02FAM/g'
but I can't work out how to also change the character in the first field on only those lines from an A to a D.
I've read a little on awk and am not sure where to go from here. Please help me. There is a system tech at work who could just write this script but I'd like to learn how to do this. I'd like to understand. All help much appreciated.