Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk limit on aix3.2.5

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Guys....
I have an awk(has to be awk on 3.2.5)solution which occasionally fails when the text is > 3000 bytes.(Awk limitation circa 1963 ???)
Could someone show the sed to do the same job for me ?

awk -v GBPT="$GBP" -v NEWT="$NEW" '
BEGIN {
RS="^C"
FS="^C"
ORS="\n"
OFS="\n"
}
{
if (index($0,"Sterling"))
print $0 >> GBPT
else
print $0 >> NEWT

}' ${IN_FILE}

TIA ;-)
Dickie Bird
db@dickiebird.freeserve.co.uk
 
how's this ? I was puzzled by the fact that you
set your RS and FS to the same character...
But anyway, try this in a script:

#!/bin/ksh

file=$1
cat $file |
tr '^C' '\012' |
grep Sterling > GBPT

# Then, same thing opposite:

cat $file |
tr '^C' '\012' |
grep -v Sterling > NEWT

# eof

Those caret C's should be entered in vi as control v,
control c.

Ciao,
quirkasaurus




 
Thanks for the reply, Quirkasaurus.
But........
The RS and FS are set to ^C so that the index statement knows what record to work on. I have several lines making up a record, terminated by ^C.
The index statement will then write the entire ^C terminated record to either of the two files, depending on the existence (or not) of the test "Sterling" line in the record.
Your routine prints just the test line to one new file and all others to the other gbp file.
Here's two sample records:
This writes to GBP file
{1:F01DDDDGB22AXXX6150963837}{2:O8981756020325FFFFESDAAXXX23531279480203251556N}{4:
:20:0208125945002058
:51C:/3409
:23:1234568/24
:30:020605
:26A:pH01128855/8859
:33B:USD500.
:73:/NAGCOM/USD2.50
:36:1.4
::34B:GBP509.93
:16A:2
:32A:GBP509.93
:72:Sterling
-}{5:{MAC:4FD745A0}{CHK:219D0ED7D5DD}}^C

This write to NEW file:
{1:F01DDDDGB22AXXX6150963837}{2:O8981756020325FFFFESDAAXXX23531279480203251556N}{4:
:20:0208125945002058
:51C:/3409
:23:1234568/24
:30:020605
:26A:pD01128855/8859
:33B:USD500.
:73:/NAGCOM/USD2.50
:36:1
::34B:USD500.00
:16A:2
:32A:USD500.00
:72:USDollar
-}{5:{MAC:4FD745A0}{CHK:219D0ED7D5DD}}^C

Any clearer ?
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
If there is a character (say \01) you can be sure will never occur in the original file, you can fix Quirkasaurus' script with additional translations:

tr '\012^C' '\01\012' <$file | grep Sterling | tr '\01' '\012' >GBPT

etc.

Pretty nasty way of doing it though. [ponder]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top