Removendo um padrão de uma string e, em seguida, armazenando a string inteira em um índice em uma matriz

0

Por isso, tenho um arquivo de muitos campos que começam com "Conteúdo:", como abaixo ...

NOTA: o conteúdo passa por várias linhas

Content:Wonderful time- even with the snow! What a great experience! From the goldfish in the room (which my daughter loved) to the fact that the valet parking staff who put on my chains on for me it was fabulous. The staff was attentive and went above and beyond to make our stay enjoyable. Oh, and about the parking: the charge is about what you would pay at any garage or lot- and I bet they wouldn't help you out in the snow! 

Date:Dec 23, 2008

No. Reader:-1

No. Helpful:-1

Overall:5

Value:4

Rooms:5

Content:Lovely hotel, unique decor, friendly front desk staff, central location It's only recently that I've started staying at boutique hotels, so I'm definitely not an expert on the subtleties that these types of establishments provide. But I've already stayed at a few Kimptons and I must say that my experiences are mostly good. Hotel Monaco is no exception. The decor at the Kimpton Hotels is always unique - they have a wonderful way of pulling off colors, textures and patterns so one feels cool and trendy yet comfortable. The lobby and lounge were decorated really nicely in very rich tones. Our room provided a nice view and had this modern, romantic, shabby-chic feel to it, for lack of a better description. All the staff was friendly and helpful without any attitude. Sazerac Restaurant served us delicious breakfast in a really great setting. Seattle is a cute town in and of itself, so the hotel only enhanced our stay. The location was ideal! We walked everywhere and had no need for a taxi. There are lots of restaurants nearby, and it only took a good 10-15 minutes to walk to Pike Place Market. From what I remember, the library is right across the street and is a must see. Gorgeous architecture. Overall, this was a nice hotel and I'd stay here again. I only gave it 4-stars because I recently stayed at a Shangri-La and was so wowed by the experience. But if I hadn't been, the Hotel Monaco would've gotten another star! 

Date:Nov 13, 2008

No. Reader:-1

No. Helpful:-1

Overall:4

Value:5

Rooms:4

Estou tentando remover a parte "Conteúdo:" usando sed e armazenar o parágrafo à direita em uma matriz em um índice.

Das respostas das pessoas até agora eu tenho

Content=( "$(sed -n -e '/<Content>.*/p' $file | cut -d">" -f2-)" )

Então, o que estou tentando conseguir é

Content[0]=Wonderful time- even with the snow! What a great experience! From the goldfish in the room (which my daughter loved) to the fact that the valet parking staff who put on my chains on for me it was fabulous. The staff was attentive and went above and beyond to make our stay enjoyable. Oh, and about the parking: the charge is about what you would pay at any garage or lot- and I bet they wouldn't help you out in the snow! 

e

Content[1]=Lovely hotel, unique decor, friendly front desk staff, central location It's only recently that I've started staying at boutique hotels, so I'm definitely not an expert on the subtleties that these types of establishments provide. But I've already stayed at a few Kimptons and I must say that my experiences are mostly good. Hotel Monaco is no exception. The decor at the Kimpton Hotels is always unique - they have a wonderful way of pulling off colors, textures and patterns so one feels cool and trendy yet comfortable. The lobby and lounge were decorated really nicely in very rich tones. Our room provided a nice view and had this modern, romantic, shabby-chic feel to it, for lack of a better description. All the staff was friendly and helpful without any attitude. Sazerac Restaurant served us delicious breakfast in a really great setting. Seattle is a cute town in and of itself, so the hotel only enhanced our stay. The location was ideal! We walked everywhere and had no need for a taxi. There are lots of restaurants nearby, and it only took a good 10-15 minutes to walk to Pike Place Market. From what I remember, the library is right across the street and is a must see. Gorgeous architecture. Overall, this was a nice hotel and I'd stay here again. I only gave it 4-stars because I recently stayed at a Shangri-La and was so wowed by the experience. But if I hadn't been, the Hotel Monaco would've gotten another star!

e assim por diante ...

Eu, então, tento percorrer este array e imprimir esta declaração:

for ((i=1; i<${arraylength}+1; i++));
    do
        echo  INSERT INTO tbl1 VALUES (${Content[$i-1]}) >> filltable.sql
    done

No entanto, junta coletivamente todo o conteúdo em uma sequência grande em vez de cada Conteúdo em seu respectivo índice

INSERT INTO tbl1 VALUES (Wonderful time- even with the snow! What a great experience! From the goldfish in the room (which my daughter loved) to the fact that the valet parking staff who put on my chains on for me it was fabulous. The staff was attentive and went above and beyond to make our stay enjoyable. Oh, and about the parking: the charge is about what you would pay at any garage or lot- and I bet they wouldn't help you out in the snow!Lovely hotel, unique decor, friendly front desk staff, central location It's only recently that I've started staying at boutique hotels, so I'm definitely not an expert on the subtleties that these types of establishments provide. But I've already stayed at a few Kimptons and I must say that my experiences are mostly good. Hotel Monaco is no exception. The decor at the Kimpton Hotels is always unique - they have a wonderful way of pulling off colors, textures and patterns so one feels cool and trendy yet comfortable. The lobby and lounge were decorated really nicely in very rich tones. Our room provided a nice view and had this modern, romantic, shabby-chic feel to it, for lack of a better description. All the staff was friendly and helpful without any attitude. Sazerac Restaurant served us delicious breakfast in a really great setting. Seattle is a cute town in and of itself, so the hotel only enhanced our stay. The location was ideal! We walked everywhere and had no need for a taxi. There are lots of restaurants nearby, and it only took a good 10-15 minutes to walk to Pike Place Market. From what I remember, the library is right across the street and is a must see. Gorgeous architecture. Overall, this was a nice hotel and I'd stay here again. I only gave it 4-stars because I recently stayed at a Shangri-La and was so wowed by the experience. But if I hadn't been, the Hotel Monaco would've gotten another star!)
    
por tom 22.04.2016 / 14:44

1 resposta

0

Este script bash usará grep para recuperar linhas começando com Content: , removerá o "Conteúdo:" principal usando os recursos de manipulação de string de bash e armazenará cada linha como um elemento de matriz:

#!/bin/bash

declare -a array=()
while read line; do
    array+=("${line##Content:}")
done < <(grep "^Content:" file)

# Display array elements
for a in "${array[@]}"; do
    echo "CONTENT: " $a
done
    
por 22.04.2016 / 15:12