Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Copy Lines between Keywords & paste them to another file Post 302897197 by newageBATMAN on Friday 11th of April 2014 11:48:01 PM
Old 04-12-2014
Signal 5 TImes Print

Quote:
Originally Posted by panyam
Something like this:

Code:
awk '/100614/ {a=$0;c=1;next} /XXXXX/&&c {b=1;next} /END/ { b=0;next} b { printf "%s %s %s \n",$0,a,FILENAME  } ' file1

Extend the same logic to handle all files.
Sorry for delayed reply, but your one liner worked like a Charm. Output is just the way I wanted.
But for every file data is appearing 5 times & 1st data is correct, but the remaining 4 times are Wrong. i.e. Suppose I ran the above line,

Test1 Test11 Test16 100614 DR3 FILE1
Test2 Test12 Test17 100614 DR3 FILE1
Test3 Test13 Test18 100614 DR3 FILE1
Test4 Test14 Test19 100614 DR3 FILE1
Test5 Test15 Test20 100614 DR3 FILE1


Test10 Test13 Test20 100614 DR3 FILE1
Test20 Test14 Test21 100614 DR3 FILE1
Test30 Test15 Test22 100614 DR3 FILE1
Test40 Test16 Test23 100614 DR3 FILE1
Test50 Test17 Test24 100614 DR3 FILE1
in the above example, 1st Paragraph data is Ok, but 2nd paragraph data is from a different date but comes with 100614 stamp

and Same thing happening for all remaining files.

Hope I 'm able to explain the issue ...

---------- Post updated at 12:15 AM ---------- Previous update was at 12:14 AM ----------

Quote:
Originally Posted by SriniShoo
If the file structure is same, below will work
Code:
awk '$1 ~ pat {for(i = 4; i < NF; i++) {printf "%s %s %s\n", $i, $1, FILENAME}}' FS='\n' RS= pat='100614' file*

Dear.. not able to test the code till now, will test & reply by tomorrow...Smilie

---------- Post updated at 09:18 AM ---------- Previous update was at 12:15 AM ----------

Quote:
Originally Posted by SriniShoo
If the file structure is same, below will work
Code:
awk '$1 ~ pat {for(i = 4; i < NF; i++) {printf "%s %s %s\n", $i, $1, FILENAME}}' FS='\n' RS= pat='100614' file*


Hi Srini...

When I run the code, there is no Op.. this is the exact code I executed in Cygwin terminal ...
awk '$1 ~ pat {for(i = 4; i < NF; i++) {printf "%s %s %s\n", $i, $1, FILENAME}}' FS='\n' RS= pat='140320' *.* > Output.log
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk/grep copy and paste and insert in between lines.

Hi all, I'm a unix newb andI'm trying to write a script that can copy some text paste it in a certian place and then add a number. It's not really clear but I'll show an example. what the file looks like right now: Linux 2.6.24-24-generic (abc) 07/15/09 23:25:01 CPU ... (6 Replies)
Discussion started by: the1hand3r
6 Replies

2. UNIX for Dummies Questions & Answers

copy and paste certain many lines of huge file in linux

Dear All, I am working with windoes OS but remote a linux machine. I wonder the way to copy an paste some part of a huge file in linux machine. the contain of file like as follow: ... dump annealling all custom 10 anneal_*.dat id type x y z q timestep 0.02 run 200000 Memory... (2 Replies)
Discussion started by: ariesto
2 Replies

3. Shell Programming and Scripting

copy the contents between two keywords to a new file.

Hi All, I want to edit my gate level netlists by searching for the content between two patterns eg: ff1 \test/a0 ( .CLK(\test/ClkInt0_acb_00x1 ),.D(\test/Rakicc ), .QB(\test/X ), .VDD(1'b1), .VSS(1'b0)); ff1 \test/a1 ( .CLK(\test/medis0_acb_00x1 ),.D(\test/hedwc ), .QB(\test/X ),... (6 Replies)
Discussion started by: naveen@
6 Replies

4. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

5. Shell Programming and Scripting

Copy a column and paste to other file question

Please help me. This is simple, but urgent problem for me. :( I have a two files file1 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 ..... file2 11 12 13 14 15 11 12 13 14 15 11 12 13 14 15 ..... 1) I hope to make a new file, file 3, that consists of 2nd... (2 Replies)
Discussion started by: exsonic
2 Replies

6. UNIX for Dummies Questions & Answers

Reading specific lines from a file using index or keywords

Hello I want to read from a file which contains email addresses. The file format is like this. from@mail.com to1@mail.com to2@mail.com cc@mail.com bcc@mail.com I'll have to read from such file and assign the email addresses to respective variables. frommail =... (11 Replies)
Discussion started by: Kyaw Lwin Phyo
11 Replies

7. Shell Programming and Scripting

Extract lines from file using keywords using script

Hi I need some lines of text from input file using keywords. Inputfile IP IS 10.238.52.65 pun-ras-bng-mhs-01#context bsnl.in Card Status : 1:0, 2:1, 3:1, 4:1, 5:0, 6:0, 7:0, 8:0, 9:1, 10:0, 11:0, 12:0, 13:0, 14:1, Max Circuits: 1: 0, 2: 32768, ... (5 Replies)
Discussion started by: surender reddy
5 Replies

8. Shell Programming and Scripting

Copy and paste text inside a xml file

I have a really big XML file. I need copy the value of one tag inside another one tag. I try to publish one example. <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1">Rai 1</channel> <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +2HD">Rai 1... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

9. Shell Programming and Scripting

Bash copy and paste text in file from one position to another

Hi I have a text file with lines beginning with 71303, 71403, 71602, I need to copy the 10 digit text at position 30 on lines beginning with 71303 (5500011446) to position 99 on every line beginning with 71602 (see example below), There may be many 71303 lines but I need the text copying to... (2 Replies)
Discussion started by: firefox2k2
2 Replies
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy