convert new line to tab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert new line to tab
# 1  
Old 03-17-2009
convert new line to tab

hey i m newbie i dont know whether this is happining in my terminal or is there any reason behind this
here it is
when i do
1.) sed -n 's/\t/\n/gp' space > enter #where space is tab seperated file
it works fine it give me a outupt that all tab seperated convert into column

but when i tried to reverse this it wount work
2.) sed -n 's/\n/\t/gp' enter > space

it wouldnt give me any output
i know there is an alternative for this
3.) cat enter | tr "\n" "\t"

i only want to know is there any reason behind the 2 case

thanx in advance
# 2  
Old 03-17-2009
your use of single-quotes negates the reg exp... Try it w double-quotes, which allow the shell to interpolate properly...
# 3  
Old 03-17-2009
no its not working after double quotes
# 4  
Old 03-17-2009
Quote:
Originally Posted by narang.mohit
hey i m newbie i dont know whether this is happining in my terminal or is there any reason behind this
here it is
when i do
1.) sed -n 's/\t/\n/gp' space > enter #where space is tab seperated file
it works fine it give me a outupt that all tab seperated convert into column

but when i tried to reverse this it wount work
2.) sed -n 's/\n/\t/gp' enter > space

There can be no newline inside a line read from a file.
Quote:

it wouldnt give me any output
i know there is an alternative for this
3.) cat enter | tr "\n" "\t"

No need for cat:

Code:
tr "\n" "\t" < enter

Or:

Code:
awk '{ printf "%s\t", $0 }' enter

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert excel to tab

Hello, I have an excel sheet (.xlsx), with 11 worksheets. I need to run my bash scripts on the 1st worksheet and write the output to the 2nd worksheet. I am currently manually converting the worksheet into a tab delimited to run the script and then pasting it back to excel. Is there a way to do... (2 Replies)
Discussion started by: nans
2 Replies

2. Shell Programming and Scripting

Convert pipe demilited file to vertical tab delimited

Hi All, How can we convert pipe delimited ( or comma ) file to vertical tab (VT) delimited. Regards PK (4 Replies)
Discussion started by: prasson_ibm
4 Replies

3. Shell Programming and Scripting

Convert mutiple spaces file to single tab

I have the following file I wanted to convert mutiple spaces to tab: I tried cat filename | tr ' ' '\t' or sed 's/ */ /' FILE but it looses the format 5557263102 5557263102 5552074858 5726310211 5557263102 5557263102 5557263103 5557263103 2142406768 ... (2 Replies)
Discussion started by: amir07
2 Replies

4. Shell Programming and Scripting

Convert tab separated text to non-trivial xml. (pwsafe --> KeePassx)

I'd like to take the output of `pwsafe --exportdb > database.txt` and convert it to a KeePassX XML friendly format (feature request in pwsafe). I found flat file converter but the syntax is beyond me with this example. Solutions are welcomed. More details Here is the pwsafe --> KeePassX XML... (2 Replies)
Discussion started by: graysky
2 Replies

5. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

6. Shell Programming and Scripting

Convert a 3 column tab delimited file to a matrix

Hi all, I have a 3 columns input file like this: CPLX9PC-4943 CPLX9PC-4943 1 CPLX9PC-4943 CpxID123 0 CPLX9PC-4943 CpxID126 0 CPLX9PC-4943 CPLX9PC-5763 0.5 CPLX9PC-4943 CpxID13 0 CPLX9PC-4943 CPLX9PC-6163 0 CPLX9PC-4943 CPLX9PC-6164 0.04... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. Shell Programming and Scripting

how to convert comma delimited file to tab separator

Hi all, How can i convert comma delimited .csv file to tab separate using sed command or script. Thanks, Krupa (4 Replies)
Discussion started by: krupasindhu18
4 Replies

8. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

9. Shell Programming and Scripting

Convert a tab separated file using bash

Dear all, I have a file in this format (like a matrix) - A B C .. X A 1 4 2 .. 2 B 2 6 4 .. 8 C 3 5 5 .. 4 . . . ... . X . . ... . and want to convert it into a file with this format: A A = 1 A B = 4 A C = 2 ... A X = 2 B A = 2 B B = 6 etc (2 Replies)
Discussion started by: TheTransporter
2 Replies

10. Shell Programming and Scripting

why convert 8 space to 1 tab character on unix?

Hi everybody, I'm using Hp unix tru64. I have generate one file from shell script. bus that file content pre "8 space char" convert one tab character. why? result file hex format: hex 20 20 20 20 20 to 09 (6 Replies)
Discussion started by: Tlg13team
6 Replies
Login or Register to Ask a Question