Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-16-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Each line dilimited by ; in output

HI,

I am having a file as under :


Code:
A3/APT "ABCDEFG" 789 120612   1501
BLOCK SUPER
R        LVB   NDV   BLO
W2JO    10    680    20

I am using the under-noted script to get the outpur as under :

Code:
awk '/^A...P.|^O/ {if(b) print b;b=$0;next} NF {b=b$0" "} END {print b}' myfile

A3/APT "ABCDEFG" 789 120612   1501      BLOCK SUPER R        LVB   NDV   BLO W2JO    10    680    20

I wanted to get the output each line delimited by ";" as under :

Code:
A3/APT "ABCDEFG" 789 120612   1501;      BLOCK SUPER; R        LVB   NDV   BLO; W2JO    10    680    20

Please suggest.
Sponsored Links
    #2  
Old 06-16-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,139
Thanks: 3
Thanked 955 Times in 934 Posts

Code:
tr '\n' ';' < file | cat - <(echo)

Sponsored Links
    #3  
Old 06-16-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by bartus11 View Post
Code:
tr '\n' ';' < file | cat - <(echo)

Thanks! But it did not succeeded in my case.
    #4  
Old 06-16-2012
Registered User
 
Join Date: Jul 2010
Posts: 15
Thanks: 7
Thanked 0 Times in 0 Posts
Lightbulb

Well, I agree wuth bartus11 though....


Code:
 
$ cat  vanand420
3/APT "ABCDEFG" 789 120612   1501
BLOCK SUPER
R        LVB   NDV   BLO
W2JO    10    680    20


Code:
$  cat  vanand420 | tr '\n' ';'
3/APT "ABCDEFG" 789 120612   1501;BLOCK SUPER;R        LVB   NDV   BLO;W2JO    10    680    20;

Sponsored Links
    #5  
Old 06-16-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dipanchandra View Post
Well, I agree wuth bartus11 though....


Code:
 
$ cat  vanand420
3/APT "ABCDEFG" 789 120612   1501
BLOCK SUPER
R        LVB   NDV   BLO
W2JO    10    680    20


Code:
$  cat  vanand420 | tr '\n' ';'
3/APT "ABCDEFG" 789 120612   1501;BLOCK SUPER;R        LVB   NDV   BLO;W2JO    10    680    20;

Thanks..might be shell issue. I am using bash on CYGWIN.
Sponsored Links
    #6  
Old 06-16-2012
Lem Lem is offline
Registered User
 
Join Date: Jun 2012
Location: Lombardia, Italy
Posts: 179
Thanks: 5
Thanked 38 Times in 38 Posts
Quote:
Originally Posted by vanand420 View Post
Thanks! But it did not succeeded in my case.
Uhm... strange. And what did happen?

However, try also this alternative:


Code:
mapfile -t line <myfile; for i in ${!line[@]}; do echo -n "${line[$i]};"; done; echo

The Following User Says Thank You to Lem For This Useful Post:
vanand420 (06-17-2012)
Sponsored Links
    #7  
Old 06-16-2012
methyl methyl is offline Forum Staff  
Moderator
 
Join Date: Mar 2008
Posts: 6,388
Thanks: 286
Thanked 668 Times in 640 Posts
@vanand420
Please post what you typed and what output was produced. Also please highlight what went wrong. I can see that a trailing semi-colon might be a problem as might be the absence of any line terminator after conversion.


Just in case:
99% of all text file processing problems on Cywin are caused because a text data file contains Microsoft line terminators (carriage_return line-feed) not unix line terminators (line_feed).
Please post the output from this enquiry on your input data file:

Code:
sed -n l filename

A line terminator displayed as just a Dollar Sign is normal for unix.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Joining multi-line output to a single line in a group gvk25 Shell Programming and Scripting 7 03-07-2012 05:22 AM
Bash - Loading a command's output line by line into an array Azrael Shell Programming and Scripting 4 09-20-2011 04:42 AM
Converting line output to column based output npatwardhan Shell Programming and Scripting 8 03-24-2010 09:40 AM
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 07:30 AM



All times are GMT -4. The time now is 04:20 PM.