The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Splitting the line in multiple lines dd_sh Shell Programming and Scripting 3 03-31-2008 10:54 AM
Line Splitting evoGage UNIX for Dummies Questions & Answers 7 11-30-2005 06:59 PM
Splitting a single line into multiple lines thanuman Shell Programming and Scripting 4 02-23-2005 01:56 AM
splitting the files sounder123 Shell Programming and Scripting 1 06-04-2004 04:03 AM
Splitting a line up lilas UNIX for Dummies Questions & Answers 1 03-12-2001 09:34 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #15  
Old 07-05-2007
Registered User
 

Join Date: May 2007
Posts: 31
Yeah, this really isn't working. This script will work with the files which contain the string

======Document
2 of 8

However, I'm now seeing that many documents I'm getting contain the string
=======Document 2 of 8

And the vast majority contain the string
==========
Document 2 of 8

I have a really nice script that will separate out all the text I need and dump it into independent text files based on the third string above.

The purpose of this exercise has been to get all the text files I'm getting formatted to appear the same way so that I could uniformly apply the splitting script.

You can see my previous efforts on that front here
http://www.unix.com/shell-programmin...-renaming.html

I don't think your script above will help with the files with the string
=======Document 2 of 8

Simon
P.S. I'll be offline for the rest of the night. If anybody has any suggestions, I'll come back to this tomorrow. Although I'm ready to dump the entire project and just do it manually. Thank you for all your help thus far!
Reply With Quote
Forum Sponsor
  #16  
Old 07-09-2007
Registered User
 

Join Date: May 2007
Posts: 31
Hi all,
I'm still having problems here and am wondering if anyone can help. I've made progress on some of my other issues and the only issue yet to resolve is splitting lines in a series of .txt files of the form "==================Document 1 of 11"
into the following
"===================
Document 1 of 11"

There are hundreds of .txt files. I'm using sed. I've tried using Dr. L's scripts above but can't for the life of me get them to work. I've tried just invoking sed at the command line and inserting newline characters; I've tried scripts with the 'N' command; nothing works.

The original files are divided into sections such as this:

==============================================================================Document 5 of 6 (Note, in the file, these digits are all on one line)












Tories under fire for taking cash from bailed-out firms; OPENING THEIR
WALLETS:[FINAL Edition]
LARRY JOHNSRUDE, Legislature Bureau Chief. Edmonton Journal. Edmonton,
Alta.:Apr 2, 1997. p. A.3

Author(s): LARRY JOHNSRUDE, Legislature Bureau Chief

Dateline: Edmonton

Section: CANADA

Publication title: Edmonton Journal. Edmonton, Alta.: Apr 2, 1997. pg. A.3

Source type: Newspaper

ProQuest document 21512919
ID:

Text Word Count 574

Document URL: http://proquest.umi.com/
pqdweb?did=21512919&Fmt=3&clientId=14119&RQT=309&VName=PQD

Abstract (Document Summary)

Alberta Conservative party officials are checking whether, in taking money from
the province's former waste treatment arm, they broke their own policy against
accepting donations from government corporations.

Alberta Special Waste Management System contributed $2,400 to Conservative
party coffers early in 1996 in the midst of a takeover by Bovar Inc., the
government's former partner in the Swan Hills plant.

Party financial records filed with Elections Alberta indicate the donation was
made Jan. 10, 1996, while the government still had a stake in the company.



Full Text (574 words)

(Copyright The Edmonton Journal)

Alberta Conservative party officials are checking whether, in taking money from
the province's former waste treatment arm, they broke their own policy against
accepting donations from government corporations.

Alberta Special Waste Management System contributed $2,400 to Conservative
party coffers early in 1996 in the midst of a takeover by Bovar Inc., the
government's former partner in the Swan Hills plant.

Party financial records filed with Elections Alberta indicate the donation was
made Jan. 10, 1996, while the government still had a stake in the company.

The province announced in July 1995 that it was paying Bovar Inc. $147.5
million to take its 40-per-cent interest in the Swan Hills plant off its hands.

The deal wasn't finalized until July 1996.

Peter Elzinga, executive director of the provincial Tories, said Tuesday he
will check on whether accepting the donation was contrary to party policy.

The Liberals say the donation was unethical.

``Even if there aren't any laws against this, you would think the government
would refuse to take money from anyone that they're negotiating with,'' said
Liberal environment critic Debby Carlson.

``It's absolutely not right. You're paying yourself with taxpayers' money.''

Bovar president Monty Davis said he saw nothing wrong with the donation, which
went to purchase a table at Premier Ralph Klein's fund-raising dinner in
Calgary.

``We wanted to hear what was being said at the dinner,'' Davis said. ``We
though it important to understand the political direction of the province.''

He said the government had only a non-financial interest in Alberta Special
Waste at the time because terms of Bovar's takeover had already been set.

The provincial Elections Act prohibits a political party from accepting
donations from government-controlled companies.

But Bill Sage, director of financial operations for Elections Alberta, said the
list of prohibited corporations didn't include Alberta Special Waste. He
suggested it may not have been on the list because the government didn't have a
controlling interest in it.

Bovar contributed $2,000 to the Conservative party last year.

Alberta Special Waste Management wasn't the only troubled company to give the
Conservatives a campaign contribution.

Cash-strapped Canadian Airlines International, which received a government-
backed loan to stay in business, contributed $4,200 to party coffers. Eaton's
Canada, currently seeking bankruptcy protection, gave $4,000.

In all, the Tories received $2.8 million in donations in 1996, which gave them
a $3-million surplus going into the March 11 election campaign.

The party had budgeted $1.7 million for the campaign. It isn't required to file
election expense statements until June.

By comparison, the Liberals received $644,000 in contributions in 1996, which
left them with a $9,900 deficit.

A Liberal party official called the deficit an accounting procedure rather than
a financial shortfall.

OPENING THEIR WALLETS

Some companies that donated to the Alberta Progressive Conservatives in 1996:

Alberta Special Waste Management Systems -- $2,400

Alberta Power Ltd. - $4,200

Amoco Canada Petroleum Co -- $13,900

[Table]

Baton Broadcasting Inc. -- $3,000

CFRN Television -- $5,000

CHED -- $800

Calgary Sun -- $600

Edmonton Sun -- $720



Canadian Airlines -- $4,200

Dow Chemical Canada Inc. -- $6,100

[Table]

Earl's Restaurants -- $10,000

Eaton's Canada -- $4,000



Edmonton Power -- $6,875

Husky Oil -- $7,500

[Table]

Imperial Oil -- $10,000

Nova Corp -- $14,400



Some companies that donated to the Alberta Liberals:

Amoco Canada

Petroleum Co. -- $7,300

[Table]

Calgary Sun -- $450

Edmonton Sun -- $500



Canwest Global Communications -- $5,000

[Table]

CFRN Television -- $450

Canadian Airlines -- $450



*** Infomart-Online ***

Credit: THE EDMONTON JOURNAL
=========================Document 6 of 6

I'm a definite newbie, but have learned a little bit through the course of the project. Simplicity is a virtue for me, as are explanations of what the various components of any script does.

I'm grateful for your time.
Reply With Quote
  #17  
Old 07-10-2007
Registered User
 

Join Date: Jul 2007
Posts: 93
the below script should work for you. I tested with the supplied file from your last post:

Note:
A. needs to be all on one line, or use a \

#!/usr/bin/ksh
( awk '$1!~/==Document/{print $0 }' $1; awk '$1~/==Document/{print substr($1,1,25) "\n" "Document" $NF }' $1)

-----------------
B. I used $1 as input, but you could easily put this inside a for loop instead,"but keep the $1's in the awk!
and substitute a variable for the $1 .
C. of course, redirect to a file with > if you want to save the output.

example:
#!/usr/bin/ksh
for INPUTT in `ls`
do

( awk '$1!~/==Document/{print $0 }' $INPUTT; awk '$1~/==Document/{print substr($1,1,25) "\n" "Document" $NF }' $INPUTT ) > ${INPUTT}_out

done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0