edit sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting edit sed command
# 1  
Old 05-29-2012
edit sed command

how can i make this sed command run faster?

Code:
sed '51000000,51347442!d' file

and

sed '51347442,$ !d' file

File is a 9GB in size.

it runs on sunos 5.10 and linux red hat 6 servers and i use bash.

Last edited by SkySmart; 05-29-2012 at 08:55 AM..
# 2  
Old 05-29-2012
Perhaps:
Code:
tail +51000000 < file | sed 347443q

Or
Code:
{ head -51000000 >/dev/null; sed 347443q; } < file

Additionally, you could try using ksh instead of bash, that might make a difference too..


--
Or maybe this even?
Code:
sed -n '51000000,51347442p;51347442q' file

or
Code:
sed '1,50999999d;51347442q' file


Last edited by Scrutinizer; 05-29-2012 at 09:21 AM..
# 3  
Old 05-29-2012
Or you could try:
Code:
awk '/51000000/{p=1};p;/51347442/{exit}' file

# 4  
Old 05-29-2012
thank you guys. i tried all the commands provided but all of them still stalls. i dont get back a command line until i CONTROL-C out of it.

basically, if i cant get the last 500,000 lines of file, i would like any amount that's the most feasible and closest to that number.

200,000, 100,000, i'll be happy with either of these.
# 5  
Old 05-29-2012
Of course it "stalls", it has to read 9 whole gigs of data before it can do anything else and tries to keep the entire 500,000 lines of data in memory at once. Processing 9 gigs of data is going to take a while no matter how you cut it, and it won't find the data it wants until it's nearly done. To get the last 500,000 lines, it has to figure out where the end is, then back up from there...

Some implementations of 'tac' however, work by seeking, which would avoid having to read the first 99% of the file. It'd deliver them in reverse order so you could just head to get the number of lines you want, then reverse it again. I'm not sure Sun's does, but it's worth a shot:

Code:
tac filename | head -n 500000 > /tmp/$$
tac /tmp/$$ > /tmp/$$-forward
rm -f /tmp/$$

If Sun's tac doesn't do that, maybe you can install GNU tac.

Last edited by Corona688; 05-29-2012 at 01:00 PM..
# 6  
Old 05-29-2012
If your file is of fixed length (meaning that each line has the same length), then you can seek to the position of the target line and read the desired number lines.
This User Gave Thanks to binlib For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inline edit using sed / awk

Hi, I have file with all the lines as following format <namebindings:StringNameSpaceBinding xmi:id="StringNameSpaceBinding" name="ENV_CONFIG_PATH" nameInNameSpace="COMP/HOD/MYSTR/BACKOFFICE/ENV_CONFIG_PATH" stringToBind="test"/> I want to replace (all the lines) value of... (8 Replies)
Discussion started by: shuklaa02
8 Replies

2. UNIX for Dummies Questions & Answers

sed to edit nth filed

Hi all, I want to edit nth filed of a comma delimited line with some value. Can I use sed command to do this. Pls suggest me the command here. Thanks, Poova. (2 Replies)
Discussion started by: poova
2 Replies

3. Shell Programming and Scripting

sed edit in place -i issues

Hello, I am attempting to create a command that I can eventually put into a loop so I can edit 1file on many servers. I would like to edit the file in place with sed -i. If not I will take any suggestions on how to use a temp file. I need to remove a email address from the configuration file... (4 Replies)
Discussion started by: abacus
4 Replies

4. Shell Programming and Scripting

Sed or Awk or both to edit file

What is an efficient way to remove all lines from the input file which contain a file name? inputfile: ======================= # comment # comment # comment 5 8 10 /tmp 5 8 10 /var/run 5 8 10 /etc/vfstab 5 8 9 /var/tmp 5 8 10 /var/adm/messages... (7 Replies)
Discussion started by: Arsenalman
7 Replies

5. Shell Programming and Scripting

Conditional edit for a field using sed

Hi I want to repalce a field in a txt file on solaris with say 100 records and each record having a total of 10 fields separated by a ~ . based on the following condition the record should be edited or else the record should be written as it is to a if the seventh field is 'XX' and if... (2 Replies)
Discussion started by: acharania2011
2 Replies

6. Shell Programming and Scripting

File edit with awk or sed

I have the follwoing file: This looks to be : seperated. For the first field i want only the file name without ".txt" and also i want to remove "+" sign if the second field starts with "+" sign. Input file: Output file: Appreciate your help (9 Replies)
Discussion started by: pinnacle
9 Replies

7. Shell Programming and Scripting

sed command to edit fields

Hi, I'm a newbie to sed and I'm having trouble working with sed and fields. Suppose I have a text file with: AAA RFG:$2.10:6:25Oct06 WDD GGTR:$3.50:5:25Oct06 ADDSJ OO:$1.37:3:26Oct07 UGBDN S:$4.73:1:27Oct06 USY ADC:$2.38:20:27Oct06 And I want to substitute field 2 of line 3 with, say,... (3 Replies)
Discussion started by: aloe_vera
3 Replies

8. Shell Programming and Scripting

SED text edit help needed

Could someone please tell me how to delete all lines above a line which contains a particular string? (possibly using SED command) I know how to do this if the target string appears in only one line of file but when it appears in multiple lines it only deletes from the first line which the string... (3 Replies)
Discussion started by: stevefox
3 Replies

9. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies

10. UNIX for Dummies Questions & Answers

edit file using sed (not create another!)

Hi, I generally use Perl for this ex. perl -e 's/pattern/replace/g' -p -i <filename> I did something like this.. find . -type f -exec perl -e 's/pattern/replace/g' -p -i {} \; I want to do this with "sed" but what I get is the output being printed on the screen.. i can do sed... (3 Replies)
Discussion started by: oldtrash
3 Replies
Login or Register to Ask a Question