To edit a portion of file.
To edit a portion of file.
am 02.11.2007 05:50:19 von Khan
Hi,
Iam new to scripting, I have a requirement where i need to edit only a
portion of file under a particulat comment.
Ex: cat file.txt
Begin of the file
#some other data
.........
#User added Forward entries
forward
forward
forward
forward
#system required Forward entries
forward
forward
forward
forward
#some other data
.........
End of the file
The requirement is to edit only Forward entries added by user without
modifying the Forward entries required by the system.
Thanks,
-Mushtaq
Re: To edit a portion of file.
am 02.11.2007 08:50:03 von PDreyer
On Nov 2, 6:50 am, khan wrote:
> Hi,
>
> Iam new to scripting, I have a requirement where i need to edit only a
> portion of file under a particulat comment.
> Ex: cat file.txt
> Begin of the file
> #some other data
> ........
> #User added Forward entries
> forward
> forward
> forward
> forward
> #system required Forward entries
> forward
> forward
> forward
> forward
> #some other data
> ........
> End of the file
> The requirement is to edit only Forward entries added by user without
> modifying the Forward entries required by the system.
>
> Thanks,
> -Mushtaq
sed '/User added Forward entries/,/system required Forward entries/ s/
ip/newip/' file.txt
Re: To edit a portion of file.
am 02.11.2007 11:59:52 von Khan
On Nov 2, 12:50 pm, PDreyer wrote:
> On Nov 2, 6:50 am, khan wrote:
>
>
>
>
>
> > Hi,
>
> > Iam new to scripting, I have a requirement where i need to edit only a
> > portion of file under a particulat comment.
> > Ex: cat file.txt
> > Begin of the file
> > #some other data
> > ........
> > #User added Forward entries
> > forward
> > forward
> > forward
> > forward
> > #system required Forward entries
> > forward
> > forward
> > forward
> > forward
> > #some other data
> > ........
> > End of the file
> > The requirement is to edit only Forward entries added by user without
> > modifying the Forward entries required by the system.
>
> > Thanks,
> > -Mushtaq
>
> sed '/User added Forward entries/,/system required Forward entries/ s/
> ip/newip/' file.txt- Hide quoted text -
>
> - Show quoted text -
Hi,
Thanks, for ur reply. Instead of subsitution, i want to delete all the
lines under #User and add the new entries.
I tried with the command: sed -e '/User added Forward entries/,/System
required Forward entries/ d'
But this command is deleting even the comments #User added Forward
entries and #System required Forward entries.
Please let me know the command to delete only the lines under #User
and till #System. And the command to insert lines under the comments.
Thanks,
Mushtaq Khan
Re: To edit a portion of file.
am 02.11.2007 12:28:13 von Ed Morton
On 11/2/2007 5:59 AM, khan wrote:
> On Nov 2, 12:50 pm, PDreyer wrote:
>
>>On Nov 2, 6:50 am, khan wrote:
>>
>>
>>
>>
>>
>>
>>>Hi,
>>
>>>Iam new to scripting, I have a requirement where i need to edit only a
>>>portion of file under a particulat comment.
>>>Ex: cat file.txt
>>>Begin of the file
>>>#some other data
>>>........
>>>#User added Forward entries
>>>forward
>>>forward
>>>forward
>>>forward
>>>#system required Forward entries
>>>forward
>>>forward
>>>forward
>>>forward
>>>#some other data
>>>........
>>>End of the file
>>>The requirement is to edit only Forward entries added by user without
>>>modifying the Forward entries required by the system.
>>
>>>Thanks,
>>>-Mushtaq
>>
>>sed '/User added Forward entries/,/system required Forward entries/ s/
>>ip/newip/' file.txt- Hide quoted text -
>>
>>- Show quoted text -
>
>
> Hi,
> Thanks, for ur reply. Instead of subsitution, i want to delete all the
> lines under #User and add the new entries.
> I tried with the command: sed -e '/User added Forward entries/,/System
> required Forward entries/ d'
> But this command is deleting even the comments #User added Forward
> entries and #System required Forward entries.
> Please let me know the command to delete only the lines under #User
> and till #System. And the command to insert lines under the comments.
> Thanks,
> Mushtaq Khan
>
awk '
/#system/ { inUser=0 }
!inUser
/#User/ {
print "first line of new stuff"
print "second line of new stuff"
inUser=1
}' file.txt
Ed
Re: To edit a portion of file.
am 02.11.2007 12:43:08 von Khan
On Nov 2, 3:59 pm, khan wrote:
> On Nov 2, 12:50 pm, PDreyer wrote:
>
>
>
>
>
> > On Nov 2, 6:50 am, khan wrote:
>
> > > Hi,
>
> > > Iam new to scripting, I have a requirement where i need to edit only a
> > > portion of file under a particulat comment.
> > > Ex: cat file.txt
> > > Begin of the file
> > > #some other data
> > > ........
> > > #User added Forward entries
> > > forward
> > > forward
> > > forward
> > > forward
> > > #system required Forward entries
> > > forward
> > > forward
> > > forward
> > > forward
> > > #some other data
> > > ........
> > > End of the file
> > > The requirement is to edit only Forward entries added by user without
> > > modifying the Forward entries required by the system.
>
> > > Thanks,
> > > -Mushtaq
>
> > sed '/User added Forward entries/,/system required Forward entries/ s/
> > ip/newip/' file.txt- Hide quoted text -
>
> > - Show quoted text -
>
> Hi,
> Thanks, for ur reply. Instead of subsitution, i want to delete all the
> lines under #User and add the new entries.
> I tried with the command: sed -e '/User added Forward entries/,/System
> required Forward entries/ d'
> But this command is deleting even the comments #User added Forward
> entries and #System required Forward entries.
> Please let me know the command to delete only the lines under #User
> and till #System. And the command to insert lines under the comments.
> Thanks,
> Mushtaq Khan- Hide quoted text -
>
> - Show quoted text -
Hi,
I got the command to delete all the lines under #User and #System, the
command is
sed -e '/User Forward/,/System/ {/Forward/d;}' file.
This part is done, but the other part to insert new entries,
Under #User and #System is still not working, please help me.
Thanks,
-Mushtaq
Re: To edit a portion of file.
am 02.11.2007 12:51:44 von Khan
On Nov 2, 4:28 pm, Ed Morton wrote:
> On 11/2/2007 5:59 AM, khan wrote:
>
>
>
>
>
> > On Nov 2, 12:50 pm, PDreyer wrote:
>
> >>On Nov 2, 6:50 am, khan wrote:
>
> >>>Hi,
>
> >>>Iam new to scripting, I have a requirement where i need to edit only a
> >>>portion of file under a particulat comment.
> >>>Ex: cat file.txt
> >>>Begin of the file
> >>>#some other data
> >>>........
> >>>#User added Forward entries
> >>>forward
> >>>forward
> >>>forward
> >>>forward
> >>>#system required Forward entries
> >>>forward
> >>>forward
> >>>forward
> >>>forward
> >>>#some other data
> >>>........
> >>>End of the file
> >>>The requirement is to edit only Forward entries added by user without
> >>>modifying the Forward entries required by the system.
>
> >>>Thanks,
> >>>-Mushtaq
>
> >>sed '/User added Forward entries/,/system required Forward entries/ s/
> >>ip/newip/' file.txt- Hide quoted text -
>
> >>- Show quoted text -
>
> > Hi,
> > Thanks, for ur reply. Instead of subsitution, i want to delete all the
> > lines under #User and add the new entries.
> > I tried with the command: sed -e '/User added Forward entries/,/System
> > required Forward entries/ d'
> > But this command is deleting even the comments #User added Forward
> > entries and #System required Forward entries.
> > Please let me know the command to delete only the lines under #User
> > and till #System. And the command to insert lines under the comments.
> > Thanks,
> > Mushtaq Khan
>
> awk '
> /#system/ { inUser=0 }
> !inUser
> /#User/ {
> print "first line of new stuff"
> print "second line of new stuff"
> inUser=1
>
> }' file.txt
>
> Ed- Hide quoted text -
>
> - Show quoted text -
Hi,
Thanks, For replying, I don't know mush about awk, please tell me what
is happening in the above code.
Thanks,
-mushtaq
Re: To edit a portion of file.
am 02.11.2007 13:06:24 von Ed Morton
On 11/2/2007 6:51 AM, khan wrote:
> On Nov 2, 4:28 pm, Ed Morton wrote:
>
>>On 11/2/2007 5:59 AM, khan wrote:
>>
>>
>>
>>
>>
>>
>>>On Nov 2, 12:50 pm, PDreyer wrote:
>>
>>>>On Nov 2, 6:50 am, khan wrote:
>>>
>>>>>Hi,
>>>>
>>>>>Iam new to scripting, I have a requirement where i need to edit only a
>>>>>portion of file under a particulat comment.
>>>>>Ex: cat file.txt
>>>>>Begin of the file
>>>>>#some other data
>>>>>........
>>>>>#User added Forward entries
>>>>>forward
>>>>>forward
>>>>>forward
>>>>>forward
>>>>>#system required Forward entries
>>>>>forward
>>>>>forward
>>>>>forward
>>>>>forward
>>>>>#some other data
>>>>>........
>>>>>End of the file
>>>>>The requirement is to edit only Forward entries added by user without
>>>>>modifying the Forward entries required by the system.
>>>>
>>>>>Thanks,
>>>>>-Mushtaq
>>>>
>>>>sed '/User added Forward entries/,/system required Forward entries/ s/
>>>>ip/newip/' file.txt- Hide quoted text -
>>>
>>>>- Show quoted text -
>>>
>>>Hi,
>>>Thanks, for ur reply. Instead of subsitution, i want to delete all the
>>>lines under #User and add the new entries.
>>>I tried with the command: sed -e '/User added Forward entries/,/System
>>>required Forward entries/ d'
>>>But this command is deleting even the comments #User added Forward
>>>entries and #System required Forward entries.
>>>Please let me know the command to delete only the lines under #User
>>>and till #System. And the command to insert lines under the comments.
>>>Thanks,
>>>Mushtaq Khan
>>
>>awk '
>>/#system/ { inUser=0 }
>>!inUser
>>/#User/ {
>> print "first line of new stuff"
>> print "second line of new stuff"
>> inUser=1
>>
>>}' file.txt
>>
>> Ed- Hide quoted text -
>>
>>- Show quoted text -
>
>
> Hi,
> Thanks, For replying, I don't know mush about awk, please tell me what
> is happening in the above code.
> Thanks,
> -mushtaq
>
Pseudo-code:
inUser = 0
while !EOF do
read line from file.txt
if line contains "#system" then
inUser = 0
endif
if inUser == 0 then
print the current line
endif
if line contains "#User" then
print "first line of new stuff"
print "second line of new stuff"
inUser = 1
endif
done
Ed.
Re: To edit a portion of file.
am 05.11.2007 16:37:48 von Khan
On Nov 2, 5:06 pm, Ed Morton wrote:
> On 11/2/2007 6:51 AM, khan wrote:
>
>
>
>
>
> > On Nov 2, 4:28 pm, Ed Morton wrote:
>
> >>On 11/2/2007 5:59 AM, khan wrote:
>
> >>>On Nov 2, 12:50 pm, PDreyer wrote:
>
> >>>>On Nov 2, 6:50 am, khan wrote:
>
> >>>>>Hi,
>
> >>>>>Iam new to scripting, I have a requirement where i need to edit only a
> >>>>>portion of file under a particulat comment.
> >>>>>Ex: cat file.txt
> >>>>>Begin of the file
> >>>>>#some other data
> >>>>>........
> >>>>>#User added Forward entries
> >>>>>forward
> >>>>>forward
> >>>>>forward
> >>>>>forward
> >>>>>#system required Forward entries
> >>>>>forward
> >>>>>forward
> >>>>>forward
> >>>>>forward
> >>>>>#some other data
> >>>>>........
> >>>>>End of the file
> >>>>>The requirement is to edit only Forward entries added by user without
> >>>>>modifying the Forward entries required by the system.
>
> >>>>>Thanks,
> >>>>>-Mushtaq
>
> >>>>sed '/User added Forward entries/,/system required Forward entries/ s/
> >>>>ip/newip/' file.txt- Hide quoted text -
>
> >>>>- Show quoted text -
>
> >>>Hi,
> >>>Thanks, for ur reply. Instead of subsitution, i want to delete all the
> >>>lines under #User and add the new entries.
> >>>I tried with the command: sed -e '/User added Forward entries/,/System
> >>>required Forward entries/ d'
> >>>But this command is deleting even the comments #User added Forward
> >>>entries and #System required Forward entries.
> >>>Please let me know the command to delete only the lines under #User
> >>>and till #System. And the command to insert lines under the comments.
> >>>Thanks,
> >>>Mushtaq Khan
>
> >>awk '
> >>/#system/ { inUser=0 }
> >>!inUser
> >>/#User/ {
> >> print "first line of new stuff"
> >> print "second line of new stuff"
> >> inUser=1
>
> >>}' file.txt
>
> >> Ed- Hide quoted text -
>
> >>- Show quoted text -
>
> > Hi,
> > Thanks, For replying, I don't know mush about awk, please tell me what
> > is happening in the above code.
> > Thanks,
> > -mushtaq
>
> Pseudo-code:
>
> inUser = 0
> while !EOF do
> read line from file.txt
> if line contains "#system" then
> inUser = 0
> endif
> if inUser == 0 then
> print the current line
> endif
> if line contains "#User" then
> print "first line of new stuff"
> print "second line of new stuff"
> inUser = 1
> endif
> done
>
> Ed.- Hide quoted text -
>
> - Show quoted text -
Hi Ed,
Iam getting syntax error while running the command you have suggested.
The Syntax error is
awk: cmd. line:1: /#system/{inuser=0} !inuser /#User/{print "stuff"}
awk: cmd. line:1: ^syntax error
The Command i ran is,
awk '/#system/ {inuser=0} !inuser /#User/{print "stuff"}' file.txt
Plz let me know if iam doing any mistake.
Thanks,
Khan
Re: To edit a portion of file.
am 05.11.2007 18:58:59 von Janis Papanagnou
khan wrote:
> On Nov 2, 5:06 pm, Ed Morton wrote:
>
>>On 11/2/2007 6:51 AM, khan wrote:
>>
>>
>>
>>
>>
>>
>>>On Nov 2, 4:28 pm, Ed Morton wrote:
>>
>>>>On 11/2/2007 5:59 AM, khan wrote:
>>
>>>>>On Nov 2, 12:50 pm, PDreyer wrote:
>>
>>>>>>On Nov 2, 6:50 am, khan wrote:
>>
>>>>>>>Hi,
>>
>>>>>>>Iam new to scripting, I have a requirement where i need to edit only a
>>>>>>>portion of file under a particulat comment.
>>>>>>>Ex: cat file.txt
>>>>>>>Begin of the file
>>>>>>>#some other data
>>>>>>>........
>>>>>>>#User added Forward entries
>>>>>>>forward
>>>>>>>forward
>>>>>>>forward
>>>>>>>forward
>>>>>>>#system required Forward entries
>>>>>>>forward
>>>>>>>forward
>>>>>>>forward
>>>>>>>forward
>>>>>>>#some other data
>>>>>>>........
>>>>>>>End of the file
>>>>>>>The requirement is to edit only Forward entries added by user without
>>>>>>>modifying the Forward entries required by the system.
>>
>>>>>>>Thanks,
>>>>>>>-Mushtaq
>>
>>>>>>sed '/User added Forward entries/,/system required Forward entries/ s/
>>>>>>ip/newip/' file.txt- Hide quoted text -
>>
>>>>>>- Show quoted text -
>>
>>>>>Hi,
>>>>>Thanks, for ur reply. Instead of subsitution, i want to delete all the
>>>>>lines under #User and add the new entries.
>>>>>I tried with the command: sed -e '/User added Forward entries/,/System
>>>>>required Forward entries/ d'
>>>>>But this command is deleting even the comments #User added Forward
>>>>>entries and #System required Forward entries.
>>>>>Please let me know the command to delete only the lines under #User
>>>>>and till #System. And the command to insert lines under the comments.
>>>>>Thanks,
>>>>>Mushtaq Khan
>>
>>>>awk '
>>>>/#system/ { inUser=0 }
>>>>!inUser
>>>>/#User/ {
>>>> print "first line of new stuff"
>>>> print "second line of new stuff"
>>>> inUser=1
>>
>>>>}' file.txt
>>
>>>> Ed- Hide quoted text -
>>
>>>>- Show quoted text -
>>
>>>Hi,
>>>Thanks, For replying, I don't know mush about awk, please tell me what
>>>is happening in the above code.
>>>Thanks,
>>>-mushtaq
>>
>>Pseudo-code:
>>
>>inUser = 0
>>while !EOF do
>> read line from file.txt
>> if line contains "#system" then
>> inUser = 0
>> endif
>> if inUser == 0 then
>> print the current line
>> endif
>> if line contains "#User" then
>> print "first line of new stuff"
>> print "second line of new stuff"
>> inUser = 1
>> endif
>>done
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
>
> Hi Ed,
> Iam getting syntax error while running the command you have suggested.
> The Syntax error is
> awk: cmd. line:1: /#system/{inuser=0} !inuser /#User/{print "stuff"}
> awk: cmd. line:1: ^syntax error
> The Command i ran is,
> awk '/#system/ {inuser=0} !inuser /#User/{print "stuff"}' file.txt
> Plz let me know if iam doing any mistake.
If you put the three condition/action parts on a single line you have
do indicate that empty action accordingly by a ';' ...
awk '/#system/ {inuser=0} !inuser ; /#User/{print "stuff"}' file.txt
Janis
> Thanks,
> Khan
>
Re: To edit a portion of file.
am 06.11.2007 06:52:24 von Khan
On Nov 5, 10:58 pm, Janis Papanagnou
wrote:
> khan wrote:
> > On Nov 2, 5:06 pm, Ed Morton wrote:
>
> >>On 11/2/2007 6:51 AM, khan wrote:
>
> >>>On Nov 2, 4:28 pm, Ed Morton wrote:
>
> >>>>On 11/2/2007 5:59 AM, khan wrote:
>
> >>>>>On Nov 2, 12:50 pm, PDreyer wrote:
>
> >>>>>>On Nov 2, 6:50 am, khan wrote:
>
> >>>>>>>Hi,
>
> >>>>>>>Iam new to scripting, I have a requirement where i need to edit only a
> >>>>>>>portion of file under a particulat comment.
> >>>>>>>Ex: cat file.txt
> >>>>>>>Begin of the file
> >>>>>>>#some other data
> >>>>>>>........
> >>>>>>>#User added Forward entries
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>#system required Forward entries
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>forward
> >>>>>>>#some other data
> >>>>>>>........
> >>>>>>>End of the file
> >>>>>>>The requirement is to edit only Forward entries added by user without
> >>>>>>>modifying the Forward entries required by the system.
>
> >>>>>>>Thanks,
> >>>>>>>-Mushtaq
>
> >>>>>>sed '/User added Forward entries/,/system required Forward entries/ s/
> >>>>>>ip/newip/' file.txt- Hide quoted text -
>
> >>>>>>- Show quoted text -
>
> >>>>>Hi,
> >>>>>Thanks, for ur reply. Instead of subsitution, i want to delete all the
> >>>>>lines under #User and add the new entries.
> >>>>>I tried with the command: sed -e '/User added Forward entries/,/System
> >>>>>required Forward entries/ d'
> >>>>>But this command is deleting even the comments #User added Forward
> >>>>>entries and #System required Forward entries.
> >>>>>Please let me know the command to delete only the lines under #User
> >>>>>and till #System. And the command to insert lines under the comments.
> >>>>>Thanks,
> >>>>>Mushtaq Khan
>
> >>>>awk '
> >>>>/#system/ { inUser=0 }
> >>>>!inUser
> >>>>/#User/ {
> >>>> print "first line of new stuff"
> >>>> print "second line of new stuff"
> >>>> inUser=1
>
> >>>>}' file.txt
>
> >>>> Ed- Hide quoted text -
>
> >>>>- Show quoted text -
>
> >>>Hi,
> >>>Thanks, For replying, I don't know mush about awk, please tell me what
> >>>is happening in the above code.
> >>>Thanks,
> >>>-mushtaq
>
> >>Pseudo-code:
>
> >>inUser = 0
> >>while !EOF do
> >> read line from file.txt
> >> if line contains "#system" then
> >> inUser = 0
> >> endif
> >> if inUser == 0 then
> >> print the current line
> >> endif
> >> if line contains "#User" then
> >> print "first line of new stuff"
> >> print "second line of new stuff"
> >> inUser = 1
> >> endif
> >>done
>
> >> Ed.- Hide quoted text -
>
> >>- Show quoted text -
>
> > Hi Ed,
> > Iam getting syntax error while running the command you have suggested.
> > The Syntax error is
> > awk: cmd. line:1: /#system/{inuser=0} !inuser /#User/{print "stuff"}
> > awk: cmd. line:1: ^syntax error
> > The Command i ran is,
> > awk '/#system/ {inuser=0} !inuser /#User/{print "stuff"}' file.txt
> > Plz let me know if iam doing any mistake.
>
> If you put the three condition/action parts on a single line you have
> do indicate that empty action accordingly by a ';' ...
>
> awk '/#system/ {inuser=0} !inuser ; /#User/{print "stuff"}' file.txt
>
> Janis
>
>
>
> > Thanks,
> > Khan- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
Thanks for both Janis and Ed Morton.
-Khan