Find the answer to your Linux question:
Results 1 to 2 of 2
Could anyone tell me the basic idea for dealing this question? The question is reformat a text into an XML-styled format. Once upon a midnight <TAB> dreary, while I pondered ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    16

    New with AWK, need help

    Could anyone tell me the basic idea for dealing this question?
    The question is reformat a text into an XML-styled format.

    Once upon a midnight <TAB> dreary, while I pondered weak and weary,
    Over many a quaint and curious volume of<Tab>forgotten lore,

    become:

    <row>
    <entry>Once upon a midnight</entry>
    <entry>dreary, while I pondered weak and weary,</entry>
    </row>
    <row>
    <entry>Over many a quaint and curious volume of<entry</entry>
    <entry>forgotten lore, </entry>
    <row>

    I am consider by reading per character, tab separated and line feed should be the case.
    How can I detect it is a tab separated and it is going to create a new line in awk ?

    note: <TAB> is tab separated. this forums ignore tap.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by ionguang View Post
    note: <TAB> is tab separated. this forums ignore tap.
    Use code tags.

    Try this:
    Code:
    awk -F "\t" '{
      print "<row>"
      for(i=1;i<=NF;i++){
        print "<entry>" $i "</entry>"
      }
      print "</row>"
    }' file > newfile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...