Script Help (sed awk)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script Help (sed awk)
# 1  
Old 07-07-2001
Script Help (sed awk)

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. Smilie
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.Smilie Smilie
# 2  
Old 07-08-2001
This is a perl method. And am not sure that it does what you mean exactly. Or wait untill someone post another (easiest) way to do the same.

perl -ni.copy -e 'if (/01PUN|01FAM/) { s/^./D/; s/01/02/; print; } else { print; }' InputFile



HTH
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk script problem

Hi All I am having a file as shown below File1# modyle 1 { test jsj hhsjh 13e3 jsjjs } memP(dbg_trace) { ajjs jsjs jsjs Test(claer) { jsjs (7 Replies)
Discussion started by: kshitij
7 Replies

2. UNIX for Dummies Questions & Answers

Use of Variables in a sed/awk script

Hi, After looking at the differents post on this forum, I am convinced that I will benefit from the experience of advanced Unix user on some script I have already done for an aeronautical study. Here is one of them : Step 1 : sed -e "s/??/00/g" Base_Awk.txt > Awk_Cut_00.txt4; sed... (11 Replies)
Discussion started by: Marc_Camoc
11 Replies

3. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

4. Shell Programming and Scripting

help with writing a awk/sed script

Hi, I thought I am getting pretty good with sed and awk, but now I dont have a way out of this question. I have a table 0.5 16 1.3 14 0.25 15 0.85 16 I want to make a column 3 which contains values that are (corresponding $2 value/sum of all $2). Please help me out here. Thanks. (6 Replies)
Discussion started by: jamie_123
6 Replies

5. Programming

Shell script using sed or awk

Hi, I want to read a file from the command line and remove all the spaces, tabs in it, replacing it with comma(,), and write it to a new file. can you help me out with this scenario. (1 Reply)
Discussion started by: sudhanshu12788
1 Replies

6. Shell Programming and Scripting

XML- Sed || Awk Bash script... Help!

Hi ! I'm working into my first bash script to make some xml modification and it's going to make me crazy lol .. so I decide to try into this forum to take some ideas from people that really know about this! This is my situation I've and xml file with a lots of positional values with another tags... (9 Replies)
Discussion started by: juampal
9 Replies

7. Shell Programming and Scripting

AWK/SED script help

Hi, was hoping someone may be able to help me with a script solution to move one line to another line from my log file: My log file currently looks like this: 01:21:12:383 Request 01:21:12:639 Response 01:21:12:386 Request 01:21:12:639 Response 01:21:12:389 Request 01:21:12:640 Response... (8 Replies)
Discussion started by: jimbobla
8 Replies

8. Shell Programming and Scripting

awk or sed script

hi guys, perhaps you can help me again I have a file generated with the AIX-tool lparstat the looks like this: %user %sys %wait %idle physc %entc lbusy app vcsw phint ----- ---- ----- ----- ----- ----- ------ --- ---- ----- 21.8 8.8 1.8 67.6 0.17 34.1 9.4 7.22 ... (3 Replies)
Discussion started by: funksen
3 Replies

9. Shell Programming and Scripting

sed or an awk script should help

num desc ind code 11 hi,feather y food 121 edible,oil y food 100 meal-pack y food 010 health,prod 120 ... (5 Replies)
Discussion started by: thumsup9
5 Replies

10. UNIX for Dummies Questions & Answers

sed/awk script

I have a file with three fields, where the first two fields are of fixed length, left justified, and right padded with spaces. The third field is truncated to the length of the data (max length 5), and possibly contains a single letter. Each field is separated by an additional space. How can I... (1 Reply)
Discussion started by: Duckman
1 Replies
Login or Register to Ask a Question