|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Remove a newline char from selected rows.
Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like Code:
abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - Code:
abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 Note - its like if in above case no of characters in a line -eq 9 (including new line char) remove newline char else not. Appreciate your help! Last edited by Franklin52; 02-03-2012 at 01:18 PM.. Reason: Please use code tags for data and code samples, thank you |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Hi mailme0205, I think there are some solutions similar in this forum, but try with this: Code:
$ cat infile
abcd1234
xyzd1234
abcd
a1b2c3d4
abcd1234
xyzd1234
xx
abcd1234
$ perl -pe 'chomp; printf qq[\n] if length != 8; END { printf qq[\n] }' infile
abcd1234xyzd1234
abcda1b2c3d4abcd1234xyzd1234
xxabcd1234Regards, Birei |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
And an awk: Code:
awk 'END{print RS} length!=8{print RS}1' ORS= infileAnd some awks can do: Code:
awk 'END{print RS} NF!=8{print RS}1' FS= ORS= infile |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SED: Place char at starting and replace selected line | hkansal | Shell Programming and Scripting | 2 | 06-11-2009 02:42 AM |
| Splitting a variable based on newline char | pavanlimo | Shell Programming and Scripting | 3 | 03-26-2009 02:18 AM |
| Need to print only selected char in a string..? | balan_mca | Shell Programming and Scripting | 2 | 10-21-2008 09:50 PM |
| How to replace any char with newline char. | mightysam | Shell Programming and Scripting | 5 | 09-18-2008 08:15 PM |
| print selected rows with awk | tonet | Shell Programming and Scripting | 6 | 09-27-2007 06:23 AM |
|
|