문자열에서 패턴을 제거하고 전체 문자열을 배열의 인덱스에 저장합니다.

문자열에서 패턴을 제거하고 전체 문자열을 배열의 인덱스에 저장합니다.

그래서 아래와 같이 "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

그러나 해당 인덱스의 각 콘텐츠가 아닌 모든 것을 하나의 큰 문자열로 연결합니다.

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

관련 정보