How to use FS for mixed file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use FS for mixed file?
# 1  
Old 03-08-2013
How to use FS for mixed file?

Hi! All

I am just wondering solution to use FS if file fields are separated by whitespace (one or more spaces ), tab and comma, How to use FS ?

finally I want to print all columns as tab separated

look at my file here tagged


Code:
130, US  121337   30.530   -58.900 1941  1 25 19.50  4183107   17,60.0,(2),[00],19.900,(3),[00]
130, US  121337   30.530   -58.900 1941  1 25 19.50  4183107   17,65.0,(2),[00],19.900,(3),[00]
130, US  121337   30.530   -58.900 1941  1 25 19.50  4183107   17,70.0,(2),[00],19.800,(3),[00]
130, US  121337   30.530   -58.900 1941  1 25 19.50  4183107   17,75.0,(2),[00],19.700,(3),[00]
130, US  121337   30.530   -58.900 1941  1 25 19.50  4183107   17,80.0,(2),[00],19.600,(3),[00]
131, US  121337   30.570   -58.970 1941  1 25 19.00  4183108   25,0.0,(1),[00],20.300,(3),[00]
131, US  121337   30.570   -58.970 1941  1 25 19.00  4183108   25,5.0,(1),[00],20.300,(3),[00]
131, US  121337   30.570   -58.970 1941  1 25 19.00  4183108   25,10.0,(2),[00],20.400,(3),[00]

# 2  
Old 03-08-2013
Code:
[ \t]*,?[ \t]*

# 3  
Old 03-08-2013
How do I use it ?

I want to print something like this

Code:
awk '{print $2,$6,$7,$13,$14}' OFS="\t" file

whether I have to use with BEGIN ?
# 4  
Old 03-08-2013
Code:
awk -F'[ \t]*,?[ \t]*' '{print $2,$6,$7,$13,$14}' OFS=\\t file

# 5  
Old 03-08-2013
I got about 80% result but few are not printing properly

kindly go through attachment
How to use FS for mixed file?-screenshotpng
# 6  
Old 03-08-2013
That is an artifact of some columns being wider than others. -54.200 is one less than a tab, so a tab moves it just one space ahead. -119.075 is one longer, so gets bumped one tab stop further along. It's still text-tab-text-tab-text-tab, not text-space-space-space-space-space-text.

Last edited by Corona688; 03-08-2013 at 02:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to parse a file with mixed formats in columns

Greetings I have a file formatted like this: rhino grey weight=1003;height=231;class=heaviest;histology=9,0,0,8 bird white weight=23;height=88;class=light;histology=7,5,1,0,0 turtle green weight=40;height=9;class=light;histology=6,0,2,0... (2 Replies)
Discussion started by: Twinklefingers
2 Replies

2. UNIX for Advanced & Expert Users

Sort mixed data file

I have a text file and each field is separated by semicolon ( ; ). Field number 7 is internally separated by comma ( , ) and pipe ( | ) symbol. I want to sort file based on three different fields which are marked in BOLD. Here first BOLD field will have numbers upto the length of 9 characters,... (6 Replies)
Discussion started by: jnrohit2k
6 Replies

3. Shell Programming and Scripting

awk - mixed for and if to select particular lines in a data file

Hi all, I am new to AWK and I am trying to solve a problem that is probably easy for an expert. Suppose I have the following data file input.txt: 20 35 43 20 23 54 20 62 21 20.5 43 12 20.5 33 11 20.5 89 87 21 33 20 21 22 21 21 56 87 I want to select from all lines having the... (4 Replies)
Discussion started by: naska
4 Replies

4. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

5. Shell Programming and Scripting

PERL - Variable values getting mixed up!

Hi, I only dip my toe into PERL programming on the odd ocassion so I was wondering if anyone had any ideas as to why the below is happening: When I run my PERL script the variable values seem to get mixed up. my $fileName = basename($maxFile,".TXT"); my $currentSeqNum =... (2 Replies)
Discussion started by: chris01010
2 Replies

6. Shell Programming and Scripting

mixed pattern match

I need to grep out patterns that matches the following. 1SR2kW-0003XW-8L Ie a pattern that contain 16 characters and will always be in the same pattern. 6 character, then a -, then 6 character, then a - then 2 character. I need a way to grep out like we grep out IP address. Here there are... (4 Replies)
Discussion started by: anil510
4 Replies

7. Shell Programming and Scripting

How do I compare mixed variables?

Searched all over can't figure out how to compare variables of alpha and numeric characters. Example a script that ask user to enter a password and then ask to repeat the password. (6 Replies)
Discussion started by: monx
6 Replies

8. Shell Programming and Scripting

Problems using multipart/mixed

Hi all I'm having trouble using MIME's multipart/mixed content type. I just try to send an email with a common body text together with an attachment (.gif). The only output I get is an empty email with no text and an invalid attachment (MS Outlook says it doesn't recognize the attachment type).... (2 Replies)
Discussion started by: Indalecio
2 Replies

9. Shell Programming and Scripting

output only numbers from mixed string

it must be late because I'm sure this is an easy task with grep sed or awk string would be anything mixing numbers letters and ) ( = output I need is just the numbers... but I just can't seem to get it to work. Any tips would be great :) (10 Replies)
Discussion started by: nortypig
10 Replies
Login or Register to Ask a Question