Cut text file in place


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut text file in place
# 1  
Old 07-16-2013
Cut text file in place

I have a file that i want to take only the first part of it and discard the rest, to be accurate,I need the first 137097 lines but I cant use split because I dont have enough space on my disck. I need sth to cut the file in its place
# 2  
Old 07-16-2013
for GNU sed, try:
Code:
sed -i -e '1,137097!d' infile

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 07-17-2013
That will still have to store its temp file somewhere, before replacing the original file.
# 4  
Old 07-17-2013
In general, 'in place' almost never is, because files do not work that way. You cannot tell a disk 'snip this line here, change that text there, and make it all line up properly'. You get to seek, overwrite, and truncate, and that's it.

And that is what you need to do here -- truncate. Figure out exactly what byte you need the file to stop at, seek to that point, then truncate the rest. What languages can you use? I'm not sure you can do this in pure shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying text file records, find data in one place in the record and print it elsewhere

Hello, I have some text data that is in the form of multi-line records. Each record ends with the string $$$$ and the next record starts on the next line. RDKit 2D 15 14 0 0 0 0 0 0 0 0999 V2000 5.4596 2.1267 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 ... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

awk to place specific contents filename within text file

I am trying to use awk to place the contens of a filename in $1 and $2 followed by the data in the text file. Basically, put the filename within the text file. There are over 1000 files in the directory and as of now each file is saved with a unique name but it is not within the file. Thank you... (10 Replies)
Discussion started by: cmccabe
10 Replies

3. UNIX for Advanced & Expert Users

Place the results of a CUT command into a variable

I am being passed a file in UNIX, ie: variable.txt I need to extract the first part of the file content, up to the period, content ie: common_dir.second_output cut -d'.' -f1 /content/stores/variable.txt I then need to utilize the results to create a variable ($1), and test on that... (4 Replies)
Discussion started by: talonbow
4 Replies

4. 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

5. Shell Programming and Scripting

Inserting text into a file but searching for the place to put it!

Hi I would love a bit of help with a problem im having with a script. I need to insert a line of text which is saved in a variable called $fwInsert into a file whos name is saved in a variable called $server but it needs to be in a certain order. The file is a forward file for a network and... (12 Replies)
Discussion started by: KatieV
12 Replies

6. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

7. 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

8. Shell Programming and Scripting

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? (4 Replies)
Discussion started by: sandy221
4 Replies

9. Shell Programming and Scripting

Perl - Enter text in a file in a place.

Hi, I have a simple question: I need to enter some text in a text file at a certain place via perl. I would first need to find that specific text in the file and then I would like to insert a line after that particular line. Say I have this text file: I am a great Perl Programmer I... (1 Reply)
Discussion started by: som.nitk
1 Replies

10. 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