Find the answer to your Linux question:
Results 1 to 3 of 3
hello all, I am a bit at a lost here I have a file with 5000 lines it is a list of books authors, series and titles all lines start ...
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    5

    create cvs from list text file

    hello all,

    I am a bit at a lost here

    I have a file with 5000 lines

    it is a list of books authors, series and titles

    all lines start with the author names, than there is a dash (-) than the series name, a dash again and the title of the book


    the problem I encounter is that sometime there is a series, sometime not, and as I try to enter this list in a database, I wanted to create a cvs file to import into mysql

    ex:
    A. A. Attanasio - Radix Tetrads 01 - Radix
    A. A. Attanasio - Solis

    the best would be to be able to add in the second line, a "space dash space" just after the author name, but how to make sure it does not do it to the first line as well

    if I could separate all line with 2 dash, (grep ??) then I would be able to do a simple replace, and change the single dash into two

    I will keep digging into it but I would really appreciate if someone would know of way to do it

    thanks

    reup

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this:
    Code:
    awk -F "-" 'NF==2{$1=$1 "- -"}1' OFS= file

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    5
    Franklin52, thanks very much for your answers

    I need to try it.

    I have found a way as well (did not sleep las night) and it is probably not as elegant but it seems to work
    Code:
    sed -e 's/-/blablabla/1' -e 's/-/bliblibli/1' list.txt > newlist.txt
    then I grep out the bliblibli
    Code:
    grep -v bliblibli newlist.txt > verygoodfilename.txt
    also the file with bliblibli
    Code:
    grep bliblibli newlist.txt > anothergoodname.txt
    therefore, I end up with 2 files, one with the series, one without

    it is a lot of work but so little compare to a hand sorting

    reup

Posting Permissions

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