@disedorgue. interesting trick with the GNU e-modifier..
I think you need 0,/^unix/.... otherwise it seems to insert twice in case the first line starts with the pattern...
This User Gave Thanks to Scrutinizer For This Post:
Hey all, thanks for you support.. What if i want the same action after 'n'th occurrence ?
Can you please help me
Hello Jagadeesh Kumar,
Let's say if you want to enter the text from Input_file2 after 5th occurrence so you could try following.
So point to not here is in above codes my condition checks for ==6though we want to insert after 5th occurrence, so whenever you want after nth occurrence to print statements then please put n+1 in condition as simple as that, I hope this helps you.
EDIT: If you want to print contents of Input_file2 on exact occurrence(let's say 5th in this example here) of string then following may help you in same too.
Thanks,
R. Singh
Last edited by RavinderSingh13; 10-03-2016 at 04:13 AM..
Reason: Added one more solution on same now.
@disedorgue. interesting trick with the GNU e-modifier..
I think you need 0,/^unix/.... otherwise it seems to insert twice in case the first line starts with the pattern...
Thanks for notice, I corrected in post.
Otherwise, always with gnu sed for n'th' occurence ( 3rd occurence in example) :
Regards.
Apologies for repeated questioning on the same.. I am very much new to this scripting. Please tell me some simple command using sed or awk (without using system) to achieve the task..
Actually i need to execute this task on a a device which taken this input inside system command.. I am not able achieve my task with the given inputs..
example:
I need to execute like system("command")
Means system will execute the command like a shell command..
---------- Post updated at 04:00 PM ---------- Previous update was at 04:00 PM ----------
Actually i need to execute this task on a a device which taken this input inside system command.. I am not able achieve my task with the given inputs..
example:
I need to execute like system("command")
Means system will execute the command like a shell command..
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by rbatte1; 10-05-2016 at 08:34 AM..
Reason: Added CODE tags.
Hi ,
I'm looking for some code that can copy and paste form file1 to file2 with 2 criterial meet.
file1:
test "sp-j1"
test "sp-j2"
test "sp-j3"
test "sp-j4"
file2:
sub Pre_Shorts1 (Status_Code, Message$)
global Status
!if Message$ <> "" then print... (3 Replies)
suppose i have original file:
original.txt:
hello
how are you
you are wonderful
what time is it
I went to the store last night. and some apple juice
then i have another file:
anotherfile.txt:
with my friends mary, john and harry.
We had a great time.
We bought food
Suppose... (1 Reply)
Hi friends, here is my problem.
I have three files like this..
cat file1.txt
=======
unix is best
unix is best
linux is best
unix is best
linux is best
linux is best
unix is best
unix is best
cat file2.txt
========
Windows performs better
Mac OS performs better
Windows... (4 Replies)
Hi,
I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g.
> cat file1
banana
apple
orange
apple
banana
pear
tangerine
apple
> cat file2
I don't like apples
What would be the sed command to insert... (5 Replies)
Hi,
I am getting crazy after days on looking at it:
Bash in Ubuntu 12.04.1
I want to do this:
pattern="system /path1/file1 file1"
new_pattern=" data /path2/file2 file2"
file to edit: data.db
- I need to search in the file data.db for the nth occurrence of pattern
- pattern must... (14 Replies)
Hi, it's my first post to this forum. I just started bash and I'm stuck at one issue. I want to include content of a file in another file after a certain line. I'm using sed for inserting one line but how to insert all content of a file ?
For example i have a file list.txt with a few lines and... (4 Replies)