Adding a file at a particular place in another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding a file at a particular place in another file
# 8  
Old 01-12-2009
Can you post a cleaner sample of your insert text, input file, and your final expected output ?

Please use code tags when posting.
The UNIX and Linux Forums - BB Code List
# 9  
Old 01-13-2009
hi

the insertion has to be done in a crontab file

the following text to insert :

# test insert
0,30 8-17 * * 1-5 . ~/.profile > /dev/null 2>&1;
#
#


this should be inserted before a line containing some words like :

## Audit du serveur

so the result shoulbe :

# test insert
0,30 8-17 * * 1-5 . ~/.profile > /dev/null 2>&1;
#
#
## Audit du serveur



regards
Christian
# 10  
Old 01-13-2009
There are already working solutions in this thread addressing your problem, anyway another alternative:

Code:
awk '/## Audit du serveur/{ system("cat insert_file") } 1' cron_file


or slightly modifying your current code:

Code:
awk   'NR==FNR{filein[n=FNR]=$0; next} /## Audit du serveur/{for(i=1;i<=n;i++) print filein[i]} 1' insert_file cron_file

# 11  
Old 01-14-2009
Thanks for your help , the 2 solutions work !

regards
Christian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Adding to an array in an external file, and adding elements to it.

I have an array in an external file, "array.txt", which contains: char *testarray={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};I want to be able to add an element to this array, and have that element display, whenever I call it, without having to recompile... (29 Replies)
Discussion started by: ignatius
29 Replies

2. Shell Programming and Scripting

Search for a file in all directories and place the file in that directory

Hi All, Daily I am getting the updated file. I have to search for this file in all directories and sub directories. If the file existed in a particular directory then move this updated file to that particular directory. If the file is not existed in any of the directories then place this... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies

3. Shell Programming and Scripting

Check file availability and place flag file

I have to check a directory on Linux (via shell Script which I am trying to build) for about 20 different source files with file patterns and if the files are made available in the directory, I should place flag files for which my other ETL jobs are waiting on to kick off. If the source files are... (6 Replies)
Discussion started by: dhruuv369
6 Replies

4. Shell Programming and Scripting

Read from file specific place in file using inode

Hello, I am using tcsh on AIX. I would like to write a script that does the following: 1. given an inode, how do I find exactly the name of the file? I know I could do this using ls -i | grep <inode> but it returns: <inode> <filename>. I need some string manipulation or something to... (1 Reply)
Discussion started by: lastZenMaster
1 Replies

5. Shell Programming and Scripting

Adding new lines to a file + adding suffix to a pattern

I need some help with adding lines to file and substitute a pattern. Ok I have a file: #cat names.txt name: John Doe stationed: 1 name: Michael Sweets stationed: 41 . . . And would like to change it to: name: John Doe employed permanently stationed: 1-office (7 Replies)
Discussion started by: hemo21
7 Replies

6. Shell Programming and Scripting

How to insert a string in a file at specified place?

Hi all, I want to insert a string in a specified place of a very large file. I am giving an example of the task: I love football. Above is a sentence in a file and I want to insert a string "the" between love and football. It is not sure that where this particular line exists. It has to... (4 Replies)
Discussion started by: naw_deepak
4 Replies

7. Shell Programming and Scripting

editing file in place

Is in Unix a tool that could do this: paste -d":" 'file1' 'file2' | special_save "file1" # so that file1 would be treated in a way that would prevent problems with race condition I know it normally doesn't work but is there any intelligent way how to avoid using temporary file? I know methods... (6 Replies)
Discussion started by: MartyIX
6 Replies

8. Shell Programming and Scripting

Jump to a specific place in a file?

If I cat a file And want to go to the first instance of a particular value - what command would I use? And then from that point where I jumped to search for another value - but only search from that point forward not before the file? Thanks~ (2 Replies)
Discussion started by: llsmr777
2 Replies

9. Shell Programming and Scripting

insert file 1 at a specific place of file 2

Hello, I need to search in file2 for class A : public B { and insert right after that the content of file1. I am a bit lost as to which tools (which bash functions, awk...). I should use. Thanks for some directions here. Regards (1 Reply)
Discussion started by: JCR
1 Replies

10. Shell Programming and Scripting

adding lines at special place in crontab

Hi , i export the crontab in a file (i've no root right) and i would add lines from a file at a special place and rewrite the output in an another file. the special place is as this : 45 04 * * * /home/toto.sh > /dev/null 2>&1 # so i would search for toto.sh and insert the lines , the... (5 Replies)
Discussion started by: Nicol
5 Replies
Login or Register to Ask a Question