0

I am trying to create file.xml, I have a city.txt file with 1000 cities, one city name per line.

The file.xml should have this format (code block) for each city from city.txt

        <ss:Row ss:Height ="22">
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">CITY-FROM-TEXT-FILE-LINE-1</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">CALIFORNIA</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">CA</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
            <ss:Cell>
               <ss:Data ss:Type="String">xx</ss:Data>
            </ss:Cell>
        </ss:Row>

What would be the best way to do that ?

Thanks

1
  • I think shell would be best, can you help me with the code please ? Commented Feb 5, 2012 at 16:17

1 Answer 1

1

You can write a awk script:

#!/usr/bin/awk -f

BEGIN{
    print "<ss:Row ss:Height='22'>"
}

{
    print "<ss:Cell>"
    print "<ss:Data ss:Type='String'>" $0 "</ss:Data>"
    print "</ss:Cell>"
}

END{
    print "</ss:Row>"    
}

To run this script:

$ awk -f xml.awk city.txt
Sign up to request clarification or add additional context in comments.

1 Comment

The output should have all the rows as in the sample code, the whole code should be one block and only the CITY-FROM-TEXT-FILE-LINE-1 should change in every block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.