Read a tab delimited


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Read a tab delimited
# 1  
Old 10-16-2008
Read a tab delimited

OK, let's set this up. I have a tab delimited file from excel. In my UNIX shell I have the following lines
Code:
   IFS=`printf "\t"`
   while read LINE_NO SKIP IGNORE_ERRORS OTHER
   do
 ....

This works fine if there is something in every column like this. NOTE, those are tabs, not spaces. Smilie
Code:
17      SKIP    FALSE   Endofline

LINE_NO=17
SKIP=SKIP
IGNORE_ERRORS=FALSE
OTHER=Endofline


The problem comes about if one of the columns is a null like this.
Code:
17                FALSE   Endofline

LINE_NO=17
SKIP=FALSE
IGNORE_ERRORS=Endofline
OTHER=

How do I get unix to see that double tab? I am on an AIX box running a ksh shell.

Thanks for your time
# 2  
Old 10-16-2008
Hmm... I had a look at an AIX box (not my usual area) and the ksh man page is a bit of a waste of time, isn't it!

Going back to a HP-UX box, it says:

Code:
    Blank Interpretation
      After parameter and command substitution, the results of substitution
      are scanned for field separator characters (found in IFS), and split
      into distinct arguments where such characters are found.  ksh retains
      explicit null arguments ( or '') but removes implicit null arguments
      (those resulting from parameters that have no values).

So it seems like you're out of luck with that particular method. Have you considered using awk or perl or is there lots of other shell code already written that depends on this part?

After experimenting a little, it seems to behave differently if you use a non-whitespace character as your IFS. So if you run your input data through sed and convert all of the separators to, say, ":", then it does appear to work as you'd expect.
# 3  
Old 10-16-2008
i suggest you change your excel delimiter to something else when you export it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

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

3. Shell Programming and Scripting

How to read data from tab delimited file after a specific position?

Hi Experts, I have a tab deliminated file as below myfile.txt Local Group Memberships *Administrators *Guests I need data in below format starting from 4th position. myfile1.txt Administrators Guests the above one is just an example and there could... (15 Replies)
Discussion started by: Litu1988
15 Replies

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

5. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

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

7. UNIX for Dummies Questions & Answers

tab delimited file that is not tab delimited.

Hi Forum I have a tab delimited file that opens well in Openoffice calc (excel). But when I perform any operation in command line, it reads the file incorrectly. When I 'save As' the same file in office as tab delimited then it works fine. The file that I think is tab delimited is actually... (8 Replies)
Discussion started by: imlearning
8 Replies

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

9. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

10. Shell Programming and Scripting

tab delimited file to commas

Hi there Just wondered if someone could help me out I have a file that has been delimited by tabs, ie field1<tab>fiield2<tab>field3 Does anybody know a command that will convert tabs to commas throughout the entire file? Note: there are a number of unpopulated fields in the file so... (6 Replies)
Discussion started by: hcclnoodles
6 Replies
Login or Register to Ask a Question