textfile into 2 pieces, seperate by newlines.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting textfile into 2 pieces, seperate by newlines.
# 8  
Old 09-24-2008
what do you mean by no difference. there must be some "important" pattern in "important text" portion that you would like to get.
# 9  
Old 09-24-2008
Code:
perl -0777 -pe 's/.*\n\n\n//ms' oldfile >newfile

The difference is the omission of the question mark after the *. This causes the match to be as long as possible instead of as short as possible. I put the "as short as possible" question mark operator in originally after some hesitation, but decided to use it as it should make the code somewhat more efficient if there is only one occurrence of three newlines.
# 10  
Old 09-24-2008
@ghostdog74: The only pattern I cant use are these three newlines.

@era: thx a lot.
# 11  
Old 09-24-2008
Quote:
Originally Posted by mcW
Theres no difference between "blabla" and "important text". I cant get a pattern for csplit. Any other ideas?
The output you want is in the file named xx01
Code:
awk 'BEGIN{FS="\n";RS=""}NR==4{print $1}' file | xargs -i csplit file /{}/

# 12  
Old 09-24-2008
Tools What about this approach?

I numbered your "important text" lines to verify the accuracy of the output.

Code:
> echo `tac infile | tr "\n" "~"` | sed "s/~~~/|/g" | cut -d"|" -f1 | tr "~" "\n" | tac
important text 1 
important text 2 
important text 3 
important text 4

# 13  
Old 09-24-2008
What's the echo and the backticks for?

Other than that, a good illustration of a best-effort workaround for avoiding Perl at any cost ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to transpose pieces of data in a column to multiple rows?

Hello Everyone, I am very new to the world of regular expressions. I am trying to use grep/sed for the following: Input file is something like this and there are multiple such files: abc 1 2 3 4 5 ***END*** abc 6 7 8 9 ***END*** abc 10 (2 Replies)
Discussion started by: shellnewuser
2 Replies

2. Shell Programming and Scripting

How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

3. Shell Programming and Scripting

Assembling the Pieces of a Regular Expression

Hello all. I'm scripting in ksh and trying to put together a regular expression. I think my logic is sound, but I'm doing the head-against-the-wall routine while trying to put the individual pieces together. Can anybody lend some suggestions to the below problem? I'm taking a date in the... (2 Replies)
Discussion started by: Michael_K
2 Replies

4. Shell Programming and Scripting

Grab 2 pieces of data within a file

I am a newbie and what I have is a captured file of content. I want to be able to grab 2 pieces of data, multiple times and print them to the screen. DataFile owner: locke user: fun data size: 60 location: Anaheim owner: david user: work data size: 80 location: Orange my script... (2 Replies)
Discussion started by: greglocke
2 Replies

5. Shell Programming and Scripting

Split a 30GB XML file into 16 pieces

I have a 30 GB XMl file which looks like this: <page> <title>APRIL</title> .........(text contents that I need to extract and store in 1.dat including the <title> tag) </page> <page> <title>August</title> ....(text contents that I need to store in 2.dat including the <title> tag) </page>... (13 Replies)
Discussion started by: shoaibjameel123
13 Replies

6. Shell Programming and Scripting

Line gets splitted into 99 char long pieces

Hello, I have a script like follows. It reads a file, and with every line, it calls an "adapter" program, which just puts the line into MQ. When I run this locally, it works fine. When I run this on our company's server, one line is split into several pieces (99 characters long) and "adapter"... (1 Reply)
Discussion started by: Adamm
1 Replies

7. Shell Programming and Scripting

How do I split file into pieces with PERL?

How do I split file into pieces with PERL? IE file.txt head 1 2 3 4 end head 5 6 7 8 9 end n so on (7 Replies)
Discussion started by: 3junior
7 Replies

8. Shell Programming and Scripting

Random pieces of number

Hello folks, i have number for example 10 and i want to divide into 4 random pieces that may be (6+2+1+1). How can i do this via script i have random number 234951 and i want to divide into 31 pieces. (6 Replies)
Discussion started by: learnbash
6 Replies

9. Shell Programming and Scripting

paste broken pieces of a record into one line

I am working with a file that has some of the records broken into several lines, I need paste the pieces back into one line. All records should start with numeric id, and presently all lines do start with id. The last field of the record is "telephone", so I need to make sure that each line starts... (1 Reply)
Discussion started by: migurus
1 Replies

10. AIX

AIX Bits and Pieces

There are quite many nifty little tricks, which can make life easier for the AIX administrator carrying out typical tasks in his job. I'll start the collection, suggestions will be highly welcome and added here when they are messaged to me. No, i don't claim to have found out myself what stands... (0 Replies)
Discussion started by: bakunin
0 Replies
Login or Register to Ask a Question