[Help me!] print text between two strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Help me!] print text between two strings
# 1  
Old 01-06-2012
print text between two strings

Deal All,

I have problem for this:

input file : "data.txt"

R 240 585694.59946146.8 8.0 239 585694.09946134.3 8.0 238 585693.59946121.8
8.01R 237 585693.09946109.3 8.0 236 585692.59946096.9 8.0 235 585692.19946084.4
8.01R 234 585691.59946071.9 8.0 233 585691.09946059.5 8.0 232 585690.59946047.0
8.01R 231 585690.09946034.5 8.0 230 585689.59946022.1 8.0 229 585688.99946009.6

8.01R 9 585676.29943265.4 8.0 8 585676.59943252.9 8.0 7 585676.99943240.4
8.01R 6 585677.29943228.0 8.0 5 585677.59943215.5 8.0 4 585677.99943203.0
8.04V0333-077 1 1002 02859.39S11746 8.45E 585561.59946596.0
56.42361531 8 S0333-077 12 1002 029 7.56S11746 7.69E 585538.29946345.4
56.42361531 8 Z0333-077 11 1002 029 7.70S11746 9.29E 585587.59946341.0
58.02361531 8 Z0333-077 12 1002 029 7.56S11746 7.69E 585538.29946345.4
58.02361531 8 T0333-077 1 1 1002 03052.83S1174612.33E 585681.19943113.3
56.42361531 8 T0333-077 1 2 1002 03053.01S11746 9.28E 585586.89943107.8
56.42361531 8 T0333-077 1 5 1002 029 8.77S11746 9.12E 585582.39946308.0
56.42361531 8 T0333-077 1 3 1002 03053.00S11746 6.32E 585495.59943108.0
56.42361531 8 T0333-077 1 4 1002 03052.85S11746 3.50E 585408.39943112.8
56.42361531 8 R 240 585694.49946166.0 8.0 239 585693.99946153.5 8.0 238
585693.49946141.0 8.01R 237 585693.09946128.6 8.0 236 585692.59946116.1 8.0 235
585692.09946103.6 8.01R 234 585691.59946091.2 8.0 233 585691.09946078.7 8.0 232
585690.59946066.2 8.01R 231 585690.09946053.7 8.0 230 585689.59946041.3 8.0 229
585675.99943259.7 8.01R 6 585676.39943247.2 8.0 5 585676.69943234.7 8.0 4
585676.99943222.2 8.01R 3 585677.39943209.7 8.0 2 585677.69943197.3 8.0 1
585405.79943186.5 8.04V0333-077 1 1003 02858.77S11746 8.45E
585561.69946615.2 60.2236153116 S0333-077 11 1003 029 7.08S11746 9.28E
585587.39946360.2 60.2236153116 Z0333-077 11 1003 029 7.08S11746 9.28E
585587.39946360.2 61.8236153116 Z0333-077 12 1003 029 6.93S11746 7.68E
585537.99946364.6 61.8236153116 T0333-077 1 1 1003 03052.19S1174612.30E
585680.29943132.7 60.2236153116 T0333-077 1 2 1003 03052.38S11746 9.26E
585586.39943127.1 60.2236153116 T0333-077 1 5 1003 029 8.15S11746 9.11E
585582.09946327.3 60.2236153116 T0333-077 1 3 1003 03052.37S11746 6.29E
585494.59943127.2 60.2236153116 T0333-077 1 4 1003 03052.23S11746 3.48E
585407.69943131.8 60.2236153116 R 240 585694.39946185.1 8.0 239
585693.89946172.6 8.0 238 585693.39946160.1 8.01R 237 585692.99946147.7 8.0 236
585692.49946135.2 8.0 235 585691.99946122.7 8.01R 234 585691.59946110.3 8.0 233
585691.09946097.8 8.0 232 585690.59946085.3 8.01R 231 585690.09946072.9 8.0 230
585689.49946060.4 8.0 229 585688.99946047.9 8.01

Desired output is as follows: "output.txt"

R 240 585694.59946146.8 8.0 239 585694.09946134.3 8.0 238 585693.59946121.8 8.01
R 237 585693.09946109.3 8.0 236 585692.59946096.9 8.0 235 585692.19946084.4 8.01
R 234 585691.59946071.9 8.0 233 585691.09946059.5 8.0 232 585690.59946047.0 8.01
R 231 585690.09946034.5 8.0 230 585689.59946022.1 8.0 229 585688.99946009.6
8.01
R 9 585676.29943265.4 8.0 8 585676.59943252.9 8.0 7 585676.99943240.4 8.01
R 6 585677.29943228.0 8.0 5 585677.59943215.5 8.0 4 585677.99943203.0 8.04
V0333-077 1 1002 02859.39S11746 8.45E 585561.59946596.0 56.42361531 8
S
0333-077 12 1002 029 7.56S11746 7.69E 585538.29946345.4 56.42361531 8
Z
0333-077 11 1002 029 7.70S11746 9.29E 585587.59946341.0 58.02361531 8
Z
0333-077 12 1002 029 7.56S11746 7.69E 585538.29946345.4 58.02361531 8
T0333-077 1 1 1002 03052.83S1174612.33E 585681.19943113.3 56.42361531 8
T
0333-077 1 2 1002 03053.01S11746 9.28E 585586.89943107.8 56.42361531 8
T
0333-077 1 5 1002 029 8.77S11746 9.12E 585582.39946308.0 56.42361531 8
T0333-077 1 3 1002 03053.00S11746 6.32E 585495.59943108.0 56.42361531 8
T
0333-077 1 4 1002 03052.85S117463.50E 585408.39943112.8 56.42361531 8
R 240 585694.49946166.0 8.0 239 585693.99946153.5 8.0 238 585693.49946141.0 8.01
R 237 585693.09946128.6 8.0 236 585692.59946116.1 8.0 235 585692.09946103.6 8.01
R 234 585691.59946091.2 8.0 233 585691.09946078.7 8.0 232 585690.59946066.2 8.01
R 231 585690.09946053.7 8.0 230 585689.59946041.3 8.0 229 585675.99943259.7 8.01
R 6 585676.39943247.2 8.0 5 585676.69943234.7 8.0 4 585676.99943222.2 8.01
R 3 585677.39943209.7 8.0 2 585677.69943197.3 8.0 1 585405.79943186.5 8.04
V0333-077 1 1003 02858.77S11746 8.45E 585561.69946615.2 60.2236153116
S0333-077 11 1003 029 7.08S11746 9.28E 585587.39946360.2 60.2236153116
Z0333-077 11 1003 029 7.08S11746 9.28E 585587.39946360.2 61.8236153116
Z0333-077 12 1003 029 6.93S11746 7.68E 585537.99946364.6 61.8236153116
T0333-077 1 1 1003 03052.19S1174612.30E 585680.29943132.7 60.2236153116
T0333-077 1 2 1003 03052.38S11746 9.26E 585586.39943127.1 60.2236153116
T0333-077 1 5 1003 029 8.15S11746 9.11E 585582.09946327.3 60.2236153116
T0333-077 1 3 1003 03052.37S11746 6.29E 585494.59943127.2 60.2236153116
T0333-077 1 4 1003 03052.23S11746 3.48E 585407.69943131.8 60.2236153116
R 240 585694.39946185.1 8.0 239 585693.89946172.6 8.0 238 585693.39946160.1 8.01
R 237 585692.99946147.7 8.0 236 585692.49946135.2 8.0 235 585691.99946122.7 8.01
R 234 585691.59946110.3 8.0 233 585691.09946097.8 8.0 232 585690.59946085.3 8.01
R 231 585690.09946072.9 8.0 230 585689.49946060.4 8.0 229 585688.99946047.9 8.01


Please, help. Tanks.

Last edited by aksin; 01-06-2012 at 10:57 AM.. Reason: wrong input data
# 2  
Old 01-06-2012
Based on the input given ..
Code:
$ nawk '{sub(/[A-Z]/,"\n&")};1' infile | nawk 'ORS=/^[0-9]/?"\n":" "'

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 01-06-2012
Code:
sed 's/\([^[:alpha:]]*\)\(.*\)/\2 \1/' yourfile

This User Gave Thanks to ctsgnb 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

Print text between 2 strings for the entire file

hey guys, for the following output: starting open open close close starting close starting open close close starting open open close open (2 Replies)
Discussion started by: boaz733
2 Replies

2. Shell Programming and Scripting

Print text between 2 identical strings

hey, i m having a hard time trying to print only the first occurrence between 2 idenicale strings. for the following output: please help me im a noob please im a noob help me noob please help me im a noob please im a noob help me noob (3 Replies)
Discussion started by: boaz733
3 Replies

3. UNIX for Dummies Questions & Answers

How to create a print filter that print text & image?

Currently, I have a print filter that takes a text file, that convert it into PCL which then gets to a HP printer. This works. Now I need to embedded a image file within the text file. I'm able to convert the image file into PCL and I can cat both files together to into a single document... (1 Reply)
Discussion started by: chedlee88-1
1 Replies

4. Programming

Print only some strings from an output

Hi, Here is an example: I have a grep line: grep -i -r -H "$WORD" "$DIRECTORY"with an output like this: /media/dir/dir2//dir4/file.txt:/media/dir/dir2/dir3/file_16072008/es6.txt: "content of the file found from grep"/media/dir/dir2/dir3/dir4/file3.txt:/media/dir/dir2/dir3//file.txt:"other... (3 Replies)
Discussion started by: Hornys
3 Replies

5. Shell Programming and Scripting

How to print few strings in a line?

I have one script which gave final output as the below statment. Successfully added Nomination Petition Manifest to the Content Manager. Now i want a sed statement which will search for this statement in any given file and print only Nomination Petition Manifest. I don't want to hardcore... (13 Replies)
Discussion started by: Vikram_Tanwar12
13 Replies

6. UNIX for Dummies Questions & Answers

How to print the text between two strings in unix.

Hi Team, Would you please help me for the below scenario. I want to print the text between "PREF:" AND "AVAIL:" in the below example. For example:- TEST_TAF PREF: RAC1 RAC2 RAC3 ...... AVAIL: RAC4 Output will be :-RAC1,RAC2,RAC3............. Thanks in Advance Shoan ... (5 Replies)
Discussion started by: shoan
5 Replies

7. Shell Programming and Scripting

[Help me!] Print text between two strings

Deal All, I have problem for this: input file : "data.txt" R 240 585694.59946146.8 8.0 239 585694.09946134.3 8.0 238 585693.59946121.8 8.01R 237 585693.09946109.3 8.0 236 585692.59946096.9 8.0 235 585692.19946084.4 8.01R 234 585691.59946071.9 8.0 233 585691.09946059.5 8.0 232... (2 Replies)
Discussion started by: aksin
2 Replies

8. UNIX for Dummies Questions & Answers

Get strings on a file and print

hi all! i have a file like this lea 25 female dave 18 male jake 27 male and i want to have an output file like this my name is lea. i am 25. female my name is dave. i am 18. male my name is jake. i am 27. male thanks! (2 Replies)
Discussion started by: engr.jay
2 Replies

9. Shell Programming and Scripting

print specific strings only

Hello, I have a file like this.. 2 168611167 STK39 STK39 --- 27347 "serine threonine kinase 39 (STE20/SPS1 homolog, yeast)" YES SNP_A-2086192 rs16854601 0.001558882 6 13670256 SIRT5 /// RPS4X SIRT5 --- 23408 /// 6191 "sirtuin (silent mating type... (5 Replies)
Discussion started by: genehunter
5 Replies

10. Shell Programming and Scripting

Print all between 2 strings

Hi All, I'm working on a large file and need to extract all data between 2 strings. I have seen many good solutions to threads almost like my problem but none that quite fit. This is all very new to me so any ideas would be really appreciated! (attempted to read sed and awk tutorials but got a... (9 Replies)
Discussion started by: soots
9 Replies
Login or Register to Ask a Question