Sponsored Content
Top Forums Shell Programming and Scripting How to convert space&tab delimited file to CSV? Post 302910158 by prvnrk on Tuesday 22nd of July 2014 08:36:02 PM
Old 07-22-2014
Quote:
Originally Posted by Chubler_XL
Can you post your input and the (undesired) output you are getting.
Code:
$ 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   HP        Ultrium 6-SCSI      J3LZ    50:03:08:c0:02:72:c0:97  F00272C097               0/0/6/1/1.145.17.255.4.0.0   /dev/rmt/c103t0d0BEST
/dev/rmt/tsmmt48   IBM       ULT3580-TD3         5AT0                             5458623002               0/0/6/1/1.145.0.255.8.0.0    /dev/rmt/c72t0d0BESTn
/dev/rmt/tsmmt53   IBM       ULT3580-TD3         5AT0                             5458623006               0/0/6/1/1.145.0.255.8.0.1    /dev/rmt/c72t0d1BESTn


$ expand test.txt | sed 's/   */,/g'
/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,HP,Ultrium 6-SCSI,J3LZ,50:03:08:c0:02:72:c0:97,F00272C097,0/0/6/1/1.145.17.255.4.0.0,/dev/rmt/c103t0d0BEST
/dev/rmt/tsmmt48,IBM,ULT3580-TD3,5AT0,5458623002,0/0/6/1/1.145.0.255.8.0.0,/dev/rmt/c72t0d0BESTn
/dev/rmt/tsmmt53,IBM,ULT3580-TD3,5AT0,5458623006,0/0/6/1/1.145.0.255.8.0.1,/dev/rmt/c72t0d1BESTn


$ sed -e 's/\t/,/g' -e 's/   */,/g' 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,HP,Ultrium 6-SCSI,J3LZ,50:03:08:c0:02:72:c0:97,F00272C097,0/0/6/1/1.145.17.255.4.0.0,/dev/rmt/c103t0d0BEST
/dev/rmt/tsmmt48,IBM,ULT3580-TD3,5AT0,5458623002,0/0/6/1/1.145.0.255.8.0.0,/dev/rmt/c72t0d0BESTn
/dev/rmt/tsmmt53,IBM,ULT3580-TD3,5AT0,5458623006,0/0/6/1/1.145.0.255.8.0.1,/dev/rmt/c72t0d1BESTn


$


Desired output
Code:
/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,HP,Ultrium 6-SCSI,J3LZ,50:03:08:c0:02:72:c0:97,F00272C097,0/0/6/1/1.145.17.255.4.0.0,/dev/rmt/c103t0d0BEST
/dev/rmt/tsmmt48,IBM,ULT3580-TD3,5AT0,,5458623002,0/0/6/1/1.145.0.255.8.0.0,/dev/rmt/c72t0d0BESTn
/dev/rmt/tsmmt53,IBM,ULT3580-TD3,5AT0,,5458623006,0/0/6/1/1.145.0.255.8.0.1,/dev/rmt/c72t0d1BESTn

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies

2. Shell Programming and Scripting

How to convert tab delimited file to .csv file

Hi, Can any one please help me in converting a tab delimited file in .csv file. Records in my file are similar to mentioned below: DET 001 0201 AC032508970 01478E1X8 DET 002 0202 AC032508971 01478E1X8 Could any one please suggest me what approach would be more suitable for this or if... (5 Replies)
Discussion started by: dtidke
5 Replies

3. 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

4. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

5. 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

6. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

10. Shell Programming and Scripting

Output file with <Tab> or <Space> Delimited

Input file: xyz,pqrs.lmno,NA,NA,NA,NA,NA,NA,NA abcd,pqrs.xyz,NA,NA,NA,NA,NA,NA,NA Expected Output: xyz pqrs.lmno NA NA NA NA NA NA NA abcd pqrs.xyz NA NA NA NA NA NA NA Command Tried so far: awk -F"," 'BEGIN{OFS=" ";} {print}' $File_Path/File_Name.csv Issue:... (5 Replies)
Discussion started by: TechGyaann
5 Replies
TABS(1) 						    BSD General Commands Manual 						   TABS(1)

NAME
tabs -- set terminal tabs SYNOPSIS
tabs [-n | -a | -a2 | -c | -c2 | -c3 | -f | -p | -s | -u] [+m[n]] [-T type] tabs [-T type] [+[n]] n1[,n2,...] DESCRIPTION
The tabs utility displays a series of characters that clear the hardware terminal tab settings then initialises tab stops at specified posi- tions, and optionally adjusts the margin. In the first synopsis form, the tab stops set depend on the command line options used, and may be one of the predefined formats or at regular intervals. In the second synopsis form, tab stops are set at positions n1, n2, etc. If a position is preceded by a '+', it is relative to the previous position set. No more than 20 positions may be specified. If no tab stops are specified, the ``standard'' UNIX tab width of 8 is used. The options are as follows: -n Set a tab stop every n columns. If n is 0, the tab stops are cleared but no new ones are set. -a Assembler format (columns 1, 10, 16, 36, 72). -a2 Assembler format (columns 1, 10, 16, 40, 72). -c COBOL normal format (columns 1, 8, 12, 16, 20, 55) -c2 COBOL compact format (columns 1, 6, 10, 14, 49) -c3 COBOL compact format (columns 1, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 67). -f FORTRAN format (columns 1, 7, 11, 15, 19, 23). -p PL/1 format (columns 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61). -s SNOBOL format (columns 1, 10, 55). -u Assembler format (columns 1, 12, 20, 44). +m[n], +[n] Set an n character left margin, or 10 if n is omitted. -T type Output escape sequence for the terminal type type. ENVIRONMENT
The LANG, LC_ALL, LC_CTYPE and TERM environment variables affect the execution of tabs as described in environ(7). The -T option overrides the setting of the TERM environment variable. If neither TERM nor the -T option are present, tabs will fail. EXIT STATUS
The tabs utility exits 0 on success, and >0 if an error occurs. SEE ALSO
expand(1), stty(1), tput(1), unexpand(1), termcap(5) STANDARDS
The tabs utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
A tabs utility appeared in PWB UNIX. This implementation was introduced in FreeBSD 5.0. BUGS
The current termcap(5) database does not define the 'ML' (set left soft margin) capability for any terminals. BSD
May 20, 2002 BSD
All times are GMT -4. The time now is 09:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy