Script required to truncate all the lines except a specific snippet.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script required to truncate all the lines except a specific snippet.
# 1  
Old 12-05-2010
Script required to truncate all the lines except a specific snippet.

Hi,

I have a file with the following structure.

XXXXX...........
YYYYY...........
.................
..................
ZZZZZZ......
qwerty_start..............
..................
.................
..................
querty_end................
...........................
............................

I need to extract the following snippet and copy to a new file.

qwerty_start..............
..................
.................
..................
querty_end................

qwerty_start and qwerty_end is just an example. i have my own keywords which vary for different files. So both should be given as a variables. (i.e) it will be read as a input while executing the script.

Can somebody please help me on getting this?

Thanks in advance.
# 2  
Old 12-05-2010
Code:
 
awk '/qwerty_start/,/querty_end/' infile > outfile

# 3  
Old 12-05-2010
Great thanks for your reply. It is working fine when hardcoded as
awk '/12345_start/,/12345_end/' test > test1

Tried to pass variable. But still i am not getting the solution.
a=12345_start
b=12345_end
awk '$a,$b' test > test2

Also tried this.

awk '/$a/,/$b/' test > test3
# 4  
Old 12-05-2010
Quote:
Originally Posted by abinash
Great thanks for your reply. It is working fine when hardcoded as
awk '/12345_start/,/12345_end/' test > test1

Tried to pass variable. But still i am not getting the solution.
a=12345_start
b=12345_end
awk '$a,$b' test > test2

Also tried this.

awk '/$a/,/$b/' test > test3
Code:
 
a=12345_start
b=12345_end
awk '/'"$a"'/,/'"$b"'/' in > out

This User Gave Thanks to malcomex999 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required deleting specific lines from file

Hi, I have a file with 20 columns of data and hundreds of lines of the same format. Here is an example line. The data repeats underneath with the same format. 15 1 4 GLY - 1 65 LYSH 23 N - 24 H - 634 O 0.188 157.552 487 48.70I have been sorting this data by hand but I was wondering if I... (3 Replies)
Discussion started by: livbaddeley
3 Replies

2. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

3. Shell Programming and Scripting

script for get lines with specific time.

i want to make a script for grep any lines with key word and every time (5 min) Ex. Log in Server. . . . 03-01-2012 03:07:54,924 - INFO MessageUtil - Return | Status=0 | TxID=12010300000548755292 | Message=Success 03-01-2012 03:09:13,789 - INFO MessageUtil - Return | Status=0 |... (6 Replies)
Discussion started by: ooilinlove
6 Replies

4. Shell Programming and Scripting

script for get lines with specific date

I'm a newbie in AIX, i want to make a script for grep any lines with date bellow 20 PRINT0089-88615 data1 3072 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88616 data1 4096 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88618 data1 5120 Mon Dec 19... (7 Replies)
Discussion started by: michlix
7 Replies

5. Shell Programming and Scripting

Script required to extract a specific snippet from the entire file.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (1 Reply)
Discussion started by: abinash
1 Replies

6. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

7. Shell Programming and Scripting

Truncate Specific Parts of a String

How do you truncate specific parts of a string. Example: 1 This is the string Goal: This is the string As you can see I'm trying to simply remove the first two characters of the string the number one and the space between the one and the word "this." Your help is appreciated. ... (8 Replies)
Discussion started by: royarellano
8 Replies

8. UNIX for Dummies Questions & Answers

AWK Pipe (truncate last few lines from file)

Hello, does anybody have a clue why the following code isn't working in csh: awk 'END{print FNR-5}' x.log | awk 'FNR<$1' x.log > x2.log I want to remove the last 5 lines of a file without using a variable. Thanks Tim (2 Replies)
Discussion started by: uxuser
2 Replies

9. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

10. Shell Programming and Scripting

Shell Script to read specific lines in a file

I have a file with contents as follows Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 6:... (5 Replies)
Discussion started by: varshanswamy
5 Replies
Login or Register to Ask a Question