Sponsored Content
Top Forums Shell Programming and Scripting Combining lines between two specific lines Post 302584970 by ppatra on Tuesday 27th of December 2011 12:50:20 AM
Old 12-27-2011
Hi,

This is the script I wrote. I'm passing a rtf file as commandline parameter, after that using awk i am praparing another file which (newfile) look like above (which i mentioned in my first post.
Code:
#!/bin/ksh
rtf_file=$1
awk '/Question:/,/Options:/{print}' $rtf_file | sed '/^$/d' > ./newfile
print=xx
n=1
while read line; do
        typeset -L9 fch=$line
        typeset -L8 fch2=$line
        if [[ $fch = 'Question:' ]]; then
                print=no
  q_no=`echo $line | tr -d "[a-z][A-Z][:]"`
                ((n+=1))
       elif [[ $fch2 = 'Options:' ]]; then
                print=no
       else
               print=yes
        fi
        if [[ $print = 'yes' ]]; then
            echo "$q_no $line"
            print=yes
        fi
done < ./newfile


The above script is giving output like below:

1 What is
1 your
1 favourite colour?
2 In which month
2 did you join
2 your first job?

But I want output like:
1 What is your favourite colour?
2 In which month did you join your first job?

PLease let me knwo if I am not clear. Thanks!

Moderator's Comments:
Mod Comment How to use code tags when posting data and code samples.

Last edited by Franklin52; 12-27-2011 at 08:33 AM.. Reason: Please use code tags for data and code samples, thank you
 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Concatenate lines between lines starting with a specific pattern

Hi, I have a file such as: --- >contig00001 length=35524 numreads=2944 gACGCCGCGCGCCGCGGCCAGGGCTGGCCCA CAGGCCGCGCGGCGTCGGCTGGCTGAG >contig00002 length=4242 numreads=43423 ATGCCGAAGGTCCGCCTGGGGCTGG CGCCGGGAGCATGTAGCG --- I would like to concatenate the lines not starting with ">"... (9 Replies)
Discussion started by: s052866
9 Replies

3. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

4. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

5. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

6. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

7. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

8. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies

9. Shell Programming and Scripting

How to find files containing two specific lines and delate those lines?

Hi I need to find files in a specified folder where are two specified lines of text and delate that lines. It looks like this" 35. ?>NL 36. <iframe>.......</iframe>NLThe problem is that "?>" is in the other lines and id should not be removed if the next line is not like "<iframe>....." So... (4 Replies)
Discussion started by: androwida
4 Replies

10. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies
spottopgm(1L)															     spottopgm(1L)

NAME
spottopgm - convert SPOT satellite images to Portable Greymap format SYNTAX
spottopgm [-1|2|3] [Firstcol Firstline Lastcol Lastline] inputfile OPTIONS
-1|2|3 Extract the given colour from the SPOT image. The colours are infra-red, visible light and ultra-violet, although I don't know which corresponds to which number. If the image is in colour, this will be announced on standard error. The default colour is 1. Firstcol Firstline Lastcol Lastline Extract the specified rectangle from the SPOT image. Most SPOT images are 3000 lines long and 3000 or more columns wide. Unfortu- nately the SPOT format only gives the width and not the length. The width is printed on standard error. The default rectangle is the width of the input image by 3000 lines. DESCRIPTION
Spottopgm converts the named inputfile into Portable Greymap format, defaulting to the first color and the whole SPOT image unless speci- fied by the options. INSTALLATION
You must edit the source program and either define BIG_ENDIAN or LITTLE_ENDIAN, and fix the typedefs for uint32_t, uint16_t and uint8_t appropriately. BUGS
Currently spottopgm doesn't determine the length of the input file; this would involve two passes over the input file. It defaults to 3000 lines instead. Spottopgm could extract a three-color image (ppm), but I didn't feel like making the program more complicated than it is now. Besides, there is no one-to-one correspondence between red, green, blue and infra-red, visible and ultra-violet. I've only had a limited number of SPOT images to play with, and therefore wouldn't guarantee that this will work on any other images. AUTHOR
Warren Toomey wkt@csadfa.cs.adfa.oz.au SEE ALSO
The rest of the Pbmplus suite. spottopgm(1L)
All times are GMT -4. The time now is 03:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy