-4
2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1

;pmEs
;0

I need this result

2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1;pmEs;0

Extra data from comment:

2015-12-21 19:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTer‌​minal=1,E1PhysPathTerm=PPS1 ;pmEs ;0
2015-12-21 09:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTer‌​minal=1,E1PhysPathTerm=PPS1 ;pmSes ;0
2015-12-21 19:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTer‌​minal=1,E1PhysPathTerm=PPS1 ;pmUas ;900
  • Is that the entire content of the file? if not, please post a more complete sample plus its desired output – steeldriver Dec 25 '15 at 2:59
  • 2015-12-21 19:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTerminal=1,E1PhysPathTerm=PPS1 ;pmEs ;0 2015-12-21 19:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTerminal=1,E1PhysPathTerm=PPS1 ;pmSes ;0 2015-12-21 19:30:00;ManagedElement=1,Equipment=1,Subrack=1,Slot=27,PlugInUnit=1,ExchangeTerminal=1,E1PhysPathTerm=PPS1 ;pmUas ;900 – Hafedh Esseyeh Dec 25 '15 at 3:08
  • 2
    Please do that by editing your question - not as a comment - so that the format is preserved – steeldriver Dec 25 '15 at 3:31
2

Given your example which looks like it could be one of many records of some kind of log, each log record starting with 2015-..., you can try this quick method:

tr -d '\n' < input.csv | sed 's/2015-/\n2015-/g' > output.csv

Explanation

  • Where input.csv contains lines looking like your example where what you want would always begin with 2015-...
  • tr -d '\n' deletes new lines. So we temporarily remove all new lines
  • < input.csv feeds the contents of input.csv to standard input, in order for tr program to read it
  • we then use sed to search for 2015- and replace with a new line preceding 2015- to get the lines back that we do want. Otherwise your input seems to be from a log and usually there are multiple entries/records in a log, just tr -d '\n' would make one huge continuous line with all different time-stamped entries merged together, and would not allow you to discern individual time-stamped entries. Thus we use this sed to ensure the final output has one record per line, via searching for a recognizable record separator such as 2015- and prefix it with a new line
  • > output.csv saves results to output.csv
  • this will not work of course if records don't start with 2015- for example we are near year's end, soon it will be 2016- so you would need to revise next year to 2016.

More Advanced Version

Or:

tr -d '\n' < input.csv | sed 's/\([[:digit:]]\{4\}\)-/\n\1-/g' > output.csv
  • works the same but for sed uses basic regular expressions to look for "year-" by looking for four digits, followed by a dash
  • so you don't have to worry about year changes
  • but just slightly more typing and harder to remember, if you aren't familiar with regular expressions yet nor have this info on you when you are required to use it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.