Cut big text file into 2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut big text file into 2
# 1  
Old 06-01-2009
Cut big text file into 2

I have a big text file. I want to cut it into 2 pieces at known point or I know the pattern of the contents from where it can separate the files. Is there any quick command/solution?
# 2  
Old 06-01-2009
See man csplit - this splits files based on context of data.
# 3  
Old 06-01-2009
Jim
Thanks for reply. Can you please let me know the syntax, I forgot to mention I am not a Unix guy.
# 4  
Old 06-01-2009
Code:
cat bigfile
a
b
c
d potter
e
f pattern
g
h
i
j

grep -n 'p.tter' bigfile
4:d potter
6:f pattern

a=$(grep -n 'p.tter' bigfile)
a=${a%%:*}
echo $a
4

head -$a bigfile
a
b
c
d potter

tail +$((a+1)) bigfile
e
f pattern
g
h
i
j

If you have csplit:
Code:
csplit bigfile '/p.tter/+1'
15
20

cat xx00
a
b
c
d potter

cat xx01
e
f pattern
g
h
i
j

csplit bigfile '/p.tter/+1' '/p.tter/+1'
15
12
8

cat xx00
a
b
c
d potter

cat xx01
e
f pattern

cat xx02
g
h
i
j


Last edited by colemar; 06-01-2009 at 11:52 AM..
# 5  
Old 06-01-2009
Thanks this has helped me solve my problem
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut text from a file and remove

Hello Friends, I am stuck with the below problem.Any help will be appreciated. I have a file which has say 100 lines. On the second last line I have a line from which i want to remove certain characters.. e.g CAST(CAST( A as varchar(50)) || ',' || CAST(CAST( B as varchar(50)) || ',' ||... (8 Replies)
Discussion started by: vital_parsley
8 Replies

2. UNIX for Dummies Questions & Answers

How to cut a big file into small ones?

Hello all, Currently I have a txt file named as a.txt with the content as: f e100 aa bb cc dd ee ff f e222 aa dd ff gg f e987 dd aa f e2222 gg ff gg aa dd ff ee ee While, for some reason I want to cut a.txt into small ones, e.g. f1.txt, f2.txt, f3.txt and f4.txt. The routine is to... (6 Replies)
Discussion started by: locohd
6 Replies

3. UNIX for Advanced & Expert Users

Help using Awk and cut with a text file

Looking for some help on using awk and cut I have a text file that has fixed information and want to write a script that will prompt the user for an account to search for and pint the output The sample line that has the key information looks like this: Statement to: ... (5 Replies)
Discussion started by: ziggy6
5 Replies

4. Shell Programming and Scripting

Very big text file - Too slow!

Hello everyone, suppose there is a very big text file (>800 mb) that each line contains an article from wikipedia. Each article begins with a tag (<..>) containing its url. Currently there are 10^6 articles in the file. I want to take random N articles, eliminate all non-alpharithmetic... (14 Replies)
Discussion started by: fedonMan
14 Replies

5. UNIX for Dummies Questions & Answers

Cut text from a file

How can I cut the text of definite length say from line no. 20 to 1000? It is trivial ques, but I am very new to Unix. Thanks :) (3 Replies)
Discussion started by: JackR
3 Replies

6. Shell Programming and Scripting

cut the second line in a text file

Hi I have some problem to cut out the second line in a output file and send to a new file it's a #!/bin/bash script 1 something 2 something 3 something and after I cut 1 something 3 something New file 2 something Thanks in advance (7 Replies)
Discussion started by: pelle
7 Replies

7. Shell Programming and Scripting

Helping in parsing subset of text from a big results file

Hi All, I need some help to effectively parse out a subset of results from a big results file. Below is an example of the text file. Each block that I need to parse starts with "reading sequence file 10.codon" (next block starts with another number) and ends with **p-Value(s)**. I have given... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

8. Shell Programming and Scripting

How to cut some data from big file

How to cut data from big file my file around 30 gb I tried "head -50022172 filename > newfile.txt ,and tail -5454283 newfile.txt. It's slowy. afer that I tried sed -n '46467831,50022172p' filename > newfile.txt ,also slow Please recommend me , faster command to cut some data from... (4 Replies)
Discussion started by: almanto
4 Replies

9. Shell Programming and Scripting

How to cut a text file at a certain spot?

Say I do a date command and get the time from 15 minutes ago. I have a text file with the date printed out every minute or so and I want to cut the file at the date stamp given to me by the 15 minute ago time stamp. Is there an easy way to do this? Example: date +%M gives me 56 I... (2 Replies)
Discussion started by: LordJezo
2 Replies
Login or Register to Ask a Question