|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Replace New Lines in Unix (Beginner)
Hi, I was wondering if anyone could help me with this problem. I have a file that looks like this, for example:
John Smith Ann Smith I want to get the text to be in 2 columns, : John Smith Ann Smith Would I be best using SED to replace the new line with a space? (How would I do this?) Or would it be better to use pr? Sorry for the mundane-ness of this Q but I've just starting on Unix! Many Thanks, Jessica |
|
#2
|
|||
|
|||
|
I am primarily a perl programmer thus I use perl:
Code:
[zby@montana SCANDIR]$ cat ~/tstfile
John
Smith
Ann
Smith
William J.
Goat
O.J.
Simple
[zby@montana SCANDIR]$
[zby@montana SCANDIR]$ cat ~/tstfile | perl -e '{while(<STDIN>) { chomp; $jm.=" $_"; if(($.%2)==0) { $jm=~s/\s+//; print "$jm\n"; $jm=""; } } }'
John Smith
Ann Smith
William J. Goat
O.J. Simple
[zby@montana SCANDIR]$
|
|
#3
|
||||
|
||||
|
Quote:
ignore that stupid 'cat' Quote:
perl -e '{while(<STDIN>) { chomp; $jm.=" $_"; if(($.%2)==0) { $jm=~s/\s+//; print "$jm\n"; $jm=""; } } }' ~/tstfile should also work (not tested) nota: this does the same sed '{N;s/\n//;}' filename |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Replace New Lines in Unix (Beginner) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|