文字列からパターンを削除し、文字列全体を配列のインデックスに保存します。

文字列からパターンを削除し、文字列全体を配列のインデックスに保存します。

そのため、以下のように「Content:」で始まる複数のフィールドを持つファイルがあります。

注:コンテンツは複数行にまたがっています。

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

sedを使用して「Content:」部分を削除し、配列のインデックスに末尾の段落を保存しようとしています。

これまでの人々の反応を通じて得たもの

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

だから私が得たいのは

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! 

そして

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!

など...

次に、この配列を繰り返して次の文を印刷します。

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

ただし、そのインデックスの各コンテンツではなく、すべてを1つの大きな文字列に連結します。

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!)

ベストアンサー1

このスクリプトは、文字列操作関数を使用して先行する「Content:」を削除し、各行を配列要素として保存してから始まる行を取得するためにbash使用されます。grepContent:bash

#!/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

おすすめ記事