It seems much wiser to use
kinda printing that line instead of deleting the others.
Regards.
The two options (2p or 2!d) are identical. It's no more wise (or otherwise) to use one (or not) over the other. The only thing sed has to do is decide whether to print the line or not. It doesn't take sed longer to decide not to print it than to print it.
The two options (2p or 2!d) are identical. It's no more wise (or otherwise) to use (or not) over the other. The only thing sed has to do is decide whether to print the line or not. It doesn't take sed longer to decide not to print it than to print it.
Hello Scottn,
when using "d" option the processing is sequential, i.e. that control iterates over and deletes over the lines except the ones specified not to. So the control has to iterate over the whole of the file and keep on deleting until the last record.
But when using "p" option as stated by me,
In the worst scenario (if you are not using hash) , if the control flows sequential
then the control iterates only until it reaches that specified line (in this case 2).
and then breaks off.
Even if the control flows to the last statement it doesnt have take any operation(unlike in the first case i.e. deleting).
Or otherwise I would take do it like this to optimize if over large files.
PS. pick what you want, dont discard what you dislike.
Hello Scottn,
when using "d" option the processing is sequential, i.e. that control iterates over and deletes over the lines except the ones specified not to. So the control has to iterate over the whole of the file and keep on deleting until the last record.
But when using "p" option as stated by me,
In the worst scenario (if you are not using hash) , if the control flows sequential
then the control iterates only until it reaches that specified line (in this case 2).
and then breaks off.
Even if the control flows to the last statement it doesnt have take any operation(unlike in the first case i.e. deleting).
Or otherwise I would take do it like this to optimize if over large files.
PS. pick what you want, dont discard what you dislike.
Hi gaurav1086.
That's all good and fine, but my statement is based on this post.
That's all good and fine, but my statement is based on this post.
And in this post the two are identical.
Hello scottn,
yeah maybe for smaller files but take a file with some 100000 records and time each of them and I bet there would be atleast slight difference in the efficiency of the two. ;-)
Thanks for reply
Regards.
Hello scottn,
yeah maybe for smaller files but take a file with some 100000 records and time each of them and I bet there would be atleast slight difference in the efficiency of the two. ;-)
Thanks for reply
Regards.
I am new to ksh scripts. I would like to be able to read a file line by line from a certain line number. I have a specific line number saved in a variable, say $lineNumber. How can I start reading the file from the line number saved in $lineNumber? Thanks! (4 Replies)
Hi all,
I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like:
<date1>|<data1>|<url1>|<result1>
<date2>|<data2>|<url2>|<result2>
<date3>|<data3>|<url3>|<result3>
<date4>|<data4>|<url4>|<result4>
What I... (3 Replies)
Hello,
I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be:
SRVXPAPI001 ERRO JUN24 07:28:34 1775
REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F
... (8 Replies)
Hi all,
I have a file sample.txt
abc
asd
adf
daf
adw
add
adv
wdf
I want to control the number of lines to read
Like if i give input as ./script_name 2 5
required output
asd
adf
daf (2 Replies)
Hello everyone,
I don't really know anything about scripting, but I have to manage to make this script, out of necessity.
#!/bin/bash
while read -r line; do #I'm reading from a big wordlist
instructions using $line
done
Is there a way to automatically write the $line number the script... (4 Replies)
I have a text file which is having 30000 lines in it. I have to create a xml file for each 10000 lines until all the lines in the text files are written. Also please help how can i get number of lines in the text file in a shell variable? (19 Replies)
Hello Everyone.
I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below:
if ; then
if ; then
tail +$1 $3 | head -n $2
else
... (5 Replies)
I am using the while-loop to read a file.
The file has lines with null-terminated strings (words, actually.)
What I have by that reading - just a first word up to '\0'!
I need to have whole string up to 'new line' - (LF, 10#10, 16#A)
What I am doing wrong?
#make file 'grb' with... (6 Replies)
Hi Everybody,
I am trying to write a script that will get some perticuler data from a file and redirect to a file.
My Question is,
I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line.
I know the line numbers, I need to get all... (9 Replies)
I have a file TXTPROCESS.TXT.20071129 in which line 1 contains the file name and rest of the records are data.
The file data looks like this:
TXTPROCESS.TXT.20071129
DIVD20071129
INTR20071129
BALN20071129
From line 2 onwards the first 4 characters defines individual process. What I... (2 Replies)