trying to reverse engineer somebodys script - what do the following lines do
when run against an input file:
sed '1,2d'
sed '2,3d'
I can see what they are doing to the data but I just want it explained for
my own sanity.
Thanks
|
|
0
|
|
|
|
Reply
|
banzai
|
8/26/2010 3:38:38 PM |
|
In article <i561fp$24q$1@usenet01.boi.hp.com>,
"banzai" <banzai@aaaa.com> wrote:
> trying to reverse engineer somebodys script - what do the following lines do
> when run against an input file:
>
> sed '1,2d'
> sed '2,3d'
>
> I can see what they are doing to the data but I just want it explained for
> my own sanity.
>
> Thanks
The first one prints all lines of the file except the first two
(eqivalent to "tail +3"). The second prints all lines of the file
except lines 2-3.
What's so confusing about them? The "d" command deletes lines, and the
prefix is a range of line numbers.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
0
|
|
|
|
Reply
|
Barry
|
8/27/2010 1:37:24 AM
|
|
On 8/26/2010 8:37 PM, Barry Margolin wrote:
> In article<i561fp$24q$1@usenet01.boi.hp.com>,
> "banzai"<banzai@aaaa.com> wrote:
>
>> trying to reverse engineer somebodys script - what do the following lines do
>> when run against an input file:
>>
>> sed '1,2d'
>> sed '2,3d'
>>
>> I can see what they are doing to the data but I just want it explained for
>> my own sanity.
>>
>> Thanks
>
> The first one prints all lines of the file except the first two
> (eqivalent to "tail +3"). The second prints all lines of the file
> except lines 2-3.
Maybe. Kinda. Depends. If what was posted represents
sed '1,2d' file
sed '2,3d' file
then it'd do what you say, but if it represents
sed '1,2d' file |
sed '2,3d'
then it'd print all but the 4th and 5th lines of the file.
Ed.
>
> What's so confusing about them? The "d" command deletes lines, and the
> prefix is a range of line numbers.
>
|
|
0
|
|
|
|
Reply
|
Ed
|
8/27/2010 3:20:18 AM
|
|
In article <i57atk$71r$1@news.eternal-september.org>,
Ed Morton <mortonspam@gmail.com> wrote:
> On 8/26/2010 8:37 PM, Barry Margolin wrote:
> > In article<i561fp$24q$1@usenet01.boi.hp.com>,
> > "banzai"<banzai@aaaa.com> wrote:
> >
> >> trying to reverse engineer somebodys script - what do the following lines
> >> do
> >> when run against an input file:
> >>
> >> sed '1,2d'
> >> sed '2,3d'
> >>
> >> I can see what they are doing to the data but I just want it explained for
> >> my own sanity.
> >>
> >> Thanks
> >
> > The first one prints all lines of the file except the first two
> > (eqivalent to "tail +3"). The second prints all lines of the file
> > except lines 2-3.
>
> Maybe. Kinda. Depends. If what was posted represents
>
> sed '1,2d' file
> sed '2,3d' file
>
> then it'd do what you say, but if it represents
>
> sed '1,2d' file |
> sed '2,3d'
>
> then it'd print all but the 4th and 5th lines of the file.
>
Sure, if you change the commands, they do different things. It will
also behave differently if you connect them with && or ||.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
0
|
|
|
|
Reply
|
Barry
|
8/28/2010 3:33:41 AM
|
|
On 8/27/2010 10:33 PM, Barry Margolin wrote:
> In article<i57atk$71r$1@news.eternal-september.org>,
> Ed Morton<mortonspam@gmail.com> wrote:
>
>> On 8/26/2010 8:37 PM, Barry Margolin wrote:
>>> In article<i561fp$24q$1@usenet01.boi.hp.com>,
>>> "banzai"<banzai@aaaa.com> wrote:
>>>
>>>> trying to reverse engineer somebodys script - what do the following lines
>>>> do
>>>> when run against an input file:
>>>>
>>>> sed '1,2d'
>>>> sed '2,3d'
>>>>
>>>> I can see what they are doing to the data but I just want it explained for
>>>> my own sanity.
>>>>
>>>> Thanks
>>>
>>> The first one prints all lines of the file except the first two
>>> (eqivalent to "tail +3"). The second prints all lines of the file
>>> except lines 2-3.
>>
>> Maybe. Kinda. Depends. If what was posted represents
>>
>> sed '1,2d' file
>> sed '2,3d' file
>>
>> then it'd do what you say, but if it represents
>>
>> sed '1,2d' file |
>> sed '2,3d'
>>
>> then it'd print all but the 4th and 5th lines of the file.
>>
>
> Sure, if you change the commands, they do different things. It will
> also behave differently if you connect them with&& or ||.
>
I wasn't changing them, I was just mentioning that depending how they're used
they could do different things. The 2 commands as written would've done nothing
at all since they weren't operating on a file or the output of a pipe. There
wouldn't be much point running them both back-to-back on the same file so there
must be something more to the way they're used than that.
Ed.
|
|
1
|
|
|
|
Reply
|
Ed
|
8/28/2010 3:51:30 AM
|
|
In article <i5a143$1ci$1@news.eternal-september.org>,
Ed Morton <mortonspam@gmail.com> wrote:
....
>I wasn't changing them, I was just mentioning that depending how
>they're used they could do different things. The 2 commands as written
>would've done nothing at all since they weren't operating on a file or
>the output of a pipe. There wouldn't be much point running them both
>back-to-back on the same file so there must be something more to the
>way they're used than that.
Ah yes, the joy of reverse engineering the real problem. Of reverse
engineering the OP's mind...
The fact is that the commands as written will most likely simply
generate an error message - so, really that's what we should be telling
OP:
% sed 1,2d file
sed: can't read file: No such file or directory
%
--
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."
- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -
|
|
0
|
|
|
|
Reply
|
gazelle
|
8/28/2010 12:35:30 PM
|
|
Sat, 28 Aug 2010 12:35:30 +0000, Kenny McCormack did cat :
> In article <i5a143$1ci$1@news.eternal-september.org>, Ed Morton
> <mortonspam@gmail.com> wrote: ...
>>I wasn't changing them, I was just mentioning that depending how they're
>>used they could do different things. The 2 commands as written would've
>>done nothing at all since they weren't operating on a file or the output
>>of a pipe. There wouldn't be much point running them both back-to-back
>>on the same file so there must be something more to the way they're used
>>than that.
>
> Ah yes, the joy of reverse engineering the real problem. Of reverse
> engineering the OP's mind...
>
> The fact is that the commands as written will most likely simply
> generate an error message - so, really that's what we should be telling
> OP:
>
> % sed 1,2d file
> sed: can't read file: No such file or directory
> %
works perfectly here and then, your implementation of
reverse-humoring must be slightly b0rken ;-)
----------
$ cat > file
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."
- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -
$ sed 1,2d file
- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -
----------
|
|
0
|
|
|
|
Reply
|
Loki
|
8/28/2010 3:26:00 PM
|
|
In article <pan.2010.08.28.15.26.00@thedarkdesign.free.fr.INVALID>,
Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote:
....
>$ cat > file
???
Where did this command come from? What makes you think you can include
that in the mix? Certainly wasn't in the OP's post - so therefore, it
just came from the recesses of your mind.
--
"We should always be disposed to believe that which appears to us to be
white is really black, if the hierarchy of the church so decides."
- Saint Ignatius Loyola (1491-1556) Founder of the Jesuit Order -
|
|
0
|
|
|
|
Reply
|
gazelle
|
8/28/2010 5:55:26 PM
|
|
Sat, 28 Aug 2010 17:55:26 +0000, Kenny McCormack did cat :
> In article <pan.2010.08.28.15.26.00@thedarkdesign.free.fr.INVALID>, Loki
> Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote: ...
>>$ cat > file
>
> ???
>
> Where did this command come from? What makes you think you can include
> that in the mix? Certainly wasn't in the OP's post
exactly like were not most of the possible questions/answers
about why/what/how/when were the few sed verbs called :-)
> - so therefore, it
> just came from the recesses of your mind.
I see you're now on the same page hence might be you read it again ;-)
|
|
0
|
|
|
|
Reply
|
Loki
|
8/28/2010 8:57:47 PM
|
|
In article <pan.2010.08.28.20.57.46@thedarkdesign.free.fr.INVALID>,
Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote:
>Sat, 28 Aug 2010 17:55:26 +0000, Kenny McCormack did cat :
>
>> In article <pan.2010.08.28.15.26.00@thedarkdesign.free.fr.INVALID>, Loki
>> Harfagr <l0k1@thedarkdesign.free.fr.INVALID> wrote: ...
>>>$ cat > file
>>
>> ???
>>
>> Where did this command come from? What makes you think you can include
>> that in the mix? Certainly wasn't in the OP's post
>
>exactly like were not most of the possible questions/answers
>about why/what/how/when were the few sed verbs called :-)
Huh? Maybe you meant to say:
>the the verbs like why/what/how/when most few possible called were were
>of sed exactly about questions/answers :-) not
>> - so therefore, it
>> just came from the recesses of your mind.
>
>I see you're now on the same page hence might be you read it again ;-)
And here, maybe you meant:
>;-) be same see it on might you page you're again the I read hence now
--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.
CLC in a nutshell.
|
|
0
|
|
|
|
Reply
|
gazelle
|
8/28/2010 9:26:47 PM
|
|
|
9 Replies
957 Views
(page loaded in 0.271 seconds)
Similiar Articles: sed - what do these lines do ? - comp.unix.shelltrying to reverse engineer somebodys script - what do the following lines do when run against an input file: sed '1,2d' sed '2,3d' I can see ... sed - add thousand separator - comp.unix.shellsed - what do these lines do ? - comp.unix.shell sed - add thousand separator - comp.unix.shell My output should be like these examples: $ echo 123456 | sed command $ 123 ... Removing trailing blank lines - comp.lang.awkRemove last lines - comp.unix.shell sed - what do these lines do ? - comp.unix.shell Do you really NEED the solution to be sed ... select last field of line (cut ... sed and new-line on Solaris broken ? - comp.unix.solaris ...Hi, if I want to replace "X" with new line, on Linux I do: echo aaaXbbb | sed 's/X/\n/g' aaa bbb Which is what I want to do. On Solaris I do same and... sed queation - remove all characters after a hyphen - comp.unix ...sed - what do these lines do ? - comp.unix.shell sed queation - remove all characters after a hyphen - comp.unix ... There's about 100 of these, so whilst doing them ... sed to insert lines in a file. - comp.unix.programmersed - what do these lines do ? - comp.unix.shell sed to insert lines in a file. - comp.unix.programmer I need to insert multiple lines into a postscript file. Retrieve string between parentheses? - comp.lang.awkIt seems much better suited for these kind of things. Thanks! -- Kind ... I need to scan for a ")" backwards from the end of the line. > > Can sed do it, or do I ... Turning line number on and off - comp.emacsIn vi, you can turning line number on and off in a file using :set nu or :set nonu. Does emacs can do the same thing? What command or key stroke to do these? sed: how to remove all duplicated white lines? - comp.unix.shell ...sed - what do these lines do ? - comp.unix.shell sed: how to remove all duplicated white lines? - comp.unix.shell ... Hi there, i'd like to write a script that removes ... sed insert - comp.lang.awk> > > >I actually do use sed fairly frequently ... pattern (SEARCH), I tryied these: awk '{print}/SEARCH/{print "ADD"}' file sed -e ... WORD' Click here to get file: sed_add_line ... sed - what do these lines do ? - comp.unix.shell | Computer Grouptrying to reverse engineer somebodys script - what do the following lines do when run against an input file: sed '1,2d' sed '2,3d' I can see ... sed, a stream editor - The GNU Operating SystemThat is, if the ! character follows an address range, then only lines which do not ... But occasionally one is committed to sticking with sed, and these commands can enable ... 7/24/2012 10:35:55 AM
|