appending lines to a file dynamically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting appending lines to a file dynamically
# 1  
Old 12-09-2011
appending lines to a file dynamically

Hi all,
I have a file with some number of lines. I need to add certain number of lines from another file which may vary according to the user's input and to it.

eg
code:
I/P
file 1
apps/file/xyz
apps/file/abc
apps/file/def
file 2
progs/file/xyz
apps/file/xyz
load \ file1
load \file2
O/P
apps/file/xyz
apps/file/abc
apps/file/def
load \ file1
load \file2


I need to append the lines which start only with load which will vary according to the user's input.

Is there any way to do it??

Thanks in advance
Ananth
# 2  
Old 12-09-2011
Code:
perl -ne 'open F,">>file1";/^load/&&print F "$_";close F' file2


Last edited by balajesuri; 12-09-2011 at 07:50 AM..
# 3  
Old 12-09-2011
Thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

2. Shell Programming and Scripting

How to dynamically fetch lines after a match?

Hi Friends, How to fetch current hour data from a log file, given below? I want all lines after the match "Wed Aug 13 16:" I have tried below command, but not working. If I put exact string, then it is working. cat /iscp/user/monitor/ORA_errors |awk '/`date +%h" "%d" "%h`/,printed==999 {... (7 Replies)
Discussion started by: suresh3566
7 Replies

3. Shell Programming and Scripting

Appending lines in a file

Hello, I have a file like: str1,"HEX"H,(39),info str2,"HEX"H,(854548),info str3,"HEX"H,'BGTOUR',info str4,"HEX"H,(534322),info str1,"HEX"H,,info str3,"HEX"H,'Landing',info str4,"HEX"H,'BG',info str1,"HEX"H,,info str3,"HEX"H,'Ay',info str1,"HEX"H,(27),info str2,"HEX"H,(854548),info... (2 Replies)
Discussion started by: apenkov
2 Replies

4. Shell Programming and Scripting

Need help on appending all the lines in a file after a pattern is found

Hi Friends, I am working on a file which has content as follows Wed,Database,ABC_cube,loaded Wed,Logging,out,user,302002654,active,for,0,minutes Wed,Logging,out,user,109000151,active,for,8,minutes Wed,Logging,out,user,302002654,active,for,0,minutes... (8 Replies)
Discussion started by: dev.devil.1983
8 Replies

5. UNIX for Dummies Questions & Answers

Grouping or appending the lines in a file through Unix

Hi, I am looking for a way to Group the Lines in a file.. Basically My file structure is something like this A 1 100 abc def A 1 200 abc def A 1 300 abc def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def I need it as... (6 Replies)
Discussion started by: mkandula1983
6 Replies

6. Shell Programming and Scripting

Grouping or appending the lines in a file through Unix

Hi, I am looking for a way to Group the Lines in a file.. Basically My file structure is something like this A 1 100 abc def A 1 200 abc def A 1 300 abc def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def I need it as... (1 Reply)
Discussion started by: mkandula1983
1 Replies

7. Shell Programming and Scripting

deleting few lines from a file dynamically

here is the part of the code var1="replicate-ignore-db" var2="replicate-same-server-id" var3="skip-slave-start" var4="report-host" var5="master-host" var6="master-user" var7="master-password" var8="master-port" #code below deleted paramters as above if exists in my.cnf for i in 1 2 3 4... (4 Replies)
Discussion started by: vivek d r
4 Replies

8. Shell Programming and Scripting

Extracting few lines from a file based on identifiers dynamically

i have something like this in a file called mysqldump.sql -- -- Table structure for table `Table11` -- DROP TABLE IF EXISTS `Table11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Table11` ( `id` int(11) NOT NULL... (14 Replies)
Discussion started by: vivek d r
14 Replies

9. Shell Programming and Scripting

Appending number of lines in the file to begining of the file

I am having 6 files named file1,file2....file6 and i need to append number of lines in each file to begining of the file. For example, If file 1 contains a b c d then after adding new line file1 should contain 4 a b c d Thanks in advance. (2 Replies)
Discussion started by: akhay_ms
2 Replies

10. Shell Programming and Scripting

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line? I have the following file that contains some blank lines and some lines I would like to append to the previous line... current file: checking dsk c19t2d6 checking dsk c19t2d7 ... (2 Replies)
Discussion started by: mr_manny
2 Replies
Login or Register to Ask a Question