Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Need to convert a pipe delimited text file to tab delimited Post 302940431 by wisecracker on Sunday 5th of April 2015 11:09:01 AM
Old 04-05-2015
Longhand using builtins only to show that it can be done, (there are much better methods), using OSX 10.7.5, default bash terminal:-
Code:
#!/bin/bash
# tab.sh
> /tmp/txt
> /tmp/text
echo "1|A|apple|A|apple
2|B|bottle|A|apple
2|B|bottle
1|A|apple
2|B|bottle
" > /tmp/txt
text=$(cat /tmp/txt)
echo "$text"
# Working part start.
count=0
while [ $count -lt ${#text} ]
do
	if [ "${text:$count:1}" = "|" ]
	then
		printf "	" >> /tmp/text
	else
		printf "${text:$count:1}" >> /tmp/text
	fi
	count=$((count+1))
done
# Replace the final newline.
echo "" >> /tmp/text
# Working part end.
cat /tmp/text
hexdump -C /tmp/text
exit 0

Results:-
Code:
Last login: Sun Apr  5 16:00:45 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> chmod 755 tab.sh
AMIGA:barrywalker~/Desktop/Code/Shell> ./tab.sh
1|A|apple|A|apple
2|B|bottle|A|apple
2|B|bottle
1|A|apple
2|B|bottle
1	A	apple	A	apple
2	B	bottle	A	apple
2	B	bottle
1	A	apple
2	B	bottle
00000000  31 09 41 09 61 70 70 6c  65 09 41 09 61 70 70 6c  |1.A.apple.A.appl|
00000010  65 0a 32 09 42 09 62 6f  74 74 6c 65 09 41 09 61  |e.2.B.bottle.A.a|
00000020  70 70 6c 65 0a 32 09 42  09 62 6f 74 74 6c 65 0a  |pple.2.B.bottle.|
00000030  31 09 41 09 61 70 70 6c  65 0a 32 09 42 09 62 6f  |1.A.apple.2.B.bo|
00000040  74 74 6c 65 0a                                    |ttle.|
00000045
AMIGA:barrywalker~/Desktop/Code/Shell> _

IMPORTANT NOTE: You have asked for TAB delimiters but have shown SPACE delimiters so be aware that this is TAB not SPACE! Hence the hexdump.
Also trailing newlines can be a problem but not in this particular case...

EDIT:
What have you attempted so far?
Also there are only nelines are carriage returns needed with the newlines too?

Last edited by wisecracker; 04-05-2015 at 01:38 PM.. Reason: See above...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert a pipe delimited file to a':" delimited file

i have a file whose data is like this:: osr_pe_assign|-120|wg000d@att.com|4| osr_evt|-21|wg000d@att.com|4| pe_avail|-21|wg000d@att.com|4| osr_svt|-11|wg000d@att.com|4| pe_mop|-13|wg000d@att.com|4| instar_ready|-35|wg000d@att.com|4| nsdnet_ready|-90|wg000d@att.com|4|... (6 Replies)
Discussion started by: priyanka3006
6 Replies

2. UNIX for Dummies Questions & Answers

How to convert text to columns in tab delimited text file

Hello Gurus, I have a text file containing nearly 12,000 tab delimited characters with 4000 rows. If the file size is small, excel can convert the text into coloumns. However, the file that I have is very big. Can some body help me in solving this problem? The input file example, ... (6 Replies)
Discussion started by: Unilearn
6 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

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

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

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 Beginners Questions & Answers

Convert Excel File (xls) to tab delimited text file on AIX

Hi i have a problem in my job i try to convert an excel file (xls extention) to text file (tab delimited), but no result with this comand cat xxx.xls > xxx.txt Do you have eny idea? PS: sorry for my english Thanks!! (4 Replies)
Discussion started by: frisso
4 Replies

10. 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
gss(5)							      BSD File Formats Manual							    gss(5)

NAME
gss -- how to configure gss framework DESCRIPTION
The gss GSS.frameworks have several configuration domains, all can configured with defaults(1). Configuration can be stored both in the user's configuration ( ~/Library/Preferences) and system ( /Library/Preferences ). CONFIGURATION OPTIONS
Use gsstool(1) to list the supported options and their settings: gsstool supported-mech --options Common options are: NTLM 'Force NTLMv1' Force client to use NTLMv1 NTLM NTLMv1 Enable support for NTLMv1 in both client and server NTLM NTLMv2 Enable support for NTLMv2 in both client and server NTLM 'NTLM session key' Require backends to support for NTLMv2 session key, Lion and earlier dont support this. Session keys is required for NTLM MIC that stops reflection attacks. NTLM 'AllowedHosts' What hosts that NTLM is allowed to be used for. When there a host that is not on the list, NTLM will not be used. File globbing is used when matching and it's case insensitive. When there is no configuration, all hosts are allowed. defaults write com.apple.GSS.NTLM AllowedHosts -array host.local '*.my.domain' NTLM options If you want to disable NTLM support completely in both the acceptor (server) and initiator (client), you need disable both NTLMv1 and NTLMv2, and set their values to boolean false or 0. defaults write com.apple.GSS.NTLM NTLMv1 -bool false defaults write com.apple.GSS.NTLM NTLMv2 -bool false APPLE MAC OS X
You can use the defaults write command to change the options, for simple boolean options, use this: defaults write com.apple.GSS.NTLM NTLMv1 -bool false You can also turn on debugging (output in syslog) using: defaults write com.apple.GSS DebugLevel -int 10 open -a Console SEE ALSO
defaults(1), gss_mo(3), heimdal_debug(1) HEIMDAL
Sep 1, 2010 HEIMDAL
All times are GMT -4. The time now is 06:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy