unknown (linux_geek) wrote in computer_help,
unknown
linux_geek
computer_help

advanced parsing

If you are bored, perhaps you can help me with this problem, its for someone on a forum I go on...



The file is formatted like this

1 crux
The problem that is the hardest to solve
The crux shadows
2 addendum
An addition
Addendum for those who submit combos
3 groggy
Half asleep and crabby
I’m groggy still
4 crabby
Grumpy
Being half asleep and crabby

(the number doesnt matter really, because that can be added in later)

And I need to get it like this

crux, The problem that is the hardest to solve, The crux shadows
addendum, an addition, Addendum...
groggy, ....

so basically it can be read into excel as a csv file.
So far I have it like this:

crux,
The problem that is the hardest to solve,
The crux shadows,

addendum,
An addition,
Addendum for those who submit combos,

groggy,
Half asleep and crabby,
I’m groggy still,

(those are commas at the ends of the lines, although they look like periods/full stops)
....

so basically i need to join up all lines with a comma at the end... any ideas??

My script reads like this so far:

cat words.txt |
sed 's/$/\,/g' | #adds commas to end of each line
tr -d '1''2''3''4''5''6''7''8''9''0' | #removes all numbers
sed 'n;n;G;' > words.csv #adds a new line every forth line


#sed -e :a -e '/\\$/N; s/\\\n//; ta' #should join up all lines with BACKSLASHES at the end

How can I modify the last line to make it join up lines ending in the commas?

Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments