Extract character between specific line numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract character between specific line numbers
# 1  
Old 04-17-2011
Extract character between specific line numbers

Hi guys,

I have txt file and I would need to extract all the contents between specific line numbers.

Code:
Line 1: apple
Line 2: orange
Line 3: mango
Line 4: grapes
Line 5: pine apple

I need to extract the content between line 2 and 4, including the contents of Line 2 and 4 so the ouput should look like
Code:
Line 2: orange
Line 3: mango
Line 4: grapes

Any help is appreciated...
# 2  
Old 04-17-2011
Code:
awk '/Line 2/, /Line 4/' data

Code:
sed -n '/Line 2/, /Line 4/ p' data

# 3  
Old 04-18-2011
Or, irrespective of the contents of those lines and aborting to avoid unnecessarily reading additional lines (useful if the files are large):

Code:
sed -n '2,4p; 4q' data

Code:
awk 'NR==2,NR==4; NR==4 {exit}' data

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract every 6-th character in a line?

Hi, I have a file consist of 25000 lines and each line has 2 columns 1 column with 6 numeric characters and 2nd one with 45000 numeric characters (not delimited). I want to take every 7th character form the 2nd column, keeping the first column. I made it in several steps but it run for 7 hours to... (7 Replies)
Discussion started by: SANDO
7 Replies

2. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

5. Shell Programming and Scripting

Remove line with specific character

HI Input :- Aog:0rt__dev_8 LAAXU24 vs.3 LAA40l0 ** LAAXU241 ** Output :- Aog:0rt__dev_8 LAAXU24 vs.3 Delete the line with ** (3 Replies)
Discussion started by: pareshkp
3 Replies

6. UNIX for Dummies Questions & Answers

Extract specific contents from each line

Hi all, Happy new year! Here I have a problem with extract specific information from each line in unix: My file is the dbSNP flat file, take two SNPs for examples: REFSNP-DOCSUM-SET (FULL-DUMP) CREATED ON: 2012-06-08 10:50 rs782 | human | 9606 | snp | genotype=NO |... (6 Replies)
Discussion started by: luoruicd
6 Replies

7. Shell Programming and Scripting

new line after specific number character

Hi All, I have input file like this: input1: ( 1083479)=T 158V 1798, T 391V 1896,T 1138V 2273,T 1547V 2477,T 2249V 2917,T 3278V 3234,T 4152V 3495,T 5500V 3631, ( 1083501)=T 181V 1851, T 459V 1954,T 810V 2141,T 1188V 2372,T 1638V 2696,T 2731V 3124,T 4799V 3640,... (5 Replies)
Discussion started by: attila
5 Replies

8. Shell Programming and Scripting

Add new line before specific character

hello all, I have file like this "infile.txt" (all data in one line) A240 582247.99974288.7 8.0 239 582248.19974301.1 8.0 238 582248.39974313.6 8.01A 237 582248.49974326.1 8.0 236 582248.69974338.6 8.0 235 582248.79974351.1 8.01A 234 582248.99974363.5 8.0 233 582249.19974376.0 8.0 232... (4 Replies)
Discussion started by: attila
4 Replies

9. Shell Programming and Scripting

How to extract first column with a specific character

Hi All, Below is the sample data of my files: O|A|571000689|D|S|PNH|S|SI sadm|ibscml1x| I|A|571000689|P|S|PNH|S|SI sadm|ibscml1x| O|A|571000689|V|S|PNH|S|SI sadm|ibscml1x| S|C|CAM|D|S|PNH|R|ZOA|2004 bscml1x| ... (3 Replies)
Discussion started by: selamba_warrior
3 Replies

10. Shell Programming and Scripting

Searching for data on a specific line numbers

Hi, I have a file on windows and have some unix utilitties available on windows. This file is very large and have over 5 million record. I am not able to open this file in Window Editor. I am trying to see bad data on a specific lines. I just have line numbers that has bad data. I need to see the... (8 Replies)
Discussion started by: rkumar28
8 Replies
Login or Register to Ask a Question