How to determine column separation format?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to determine column separation format?
# 1  
Old 10-16-2015
How to determine column separation format?

Hi there,

say I have a line with multiple columns but with different separation formats: spaces, tabs..

Is it possible to have AWK print the separation format between each column?
# 2  
Old 10-16-2015
If you supply any other means to identify columns and/or tell them from each other.
# 3  
Old 10-16-2015
Thank you, but I dont think I got your point
# 4  
Old 10-16-2015
You didn't supply any way for a program looking at your input file to determine whether a one or more spaces or one or more tabs found in a line in that input file is supposed to be interpreted as a field separator or as data within a field. And since you said the separation formats include spaces, tabs, ...; we don't know whether any given character in the input file is a field separator or data.

If you can't explicitly explain the difference between data and field separators in your input, there is nothing we can do to help you write an awk script that will determine the format for you.
# 5  
Old 10-16-2015
Ok, thank you. The file looks like this:

Code:
ABCD      A  L     BBB J HHH     9495994 4458902  HJFGGJK  SDFR 22222

Can awk determine which are the separators between ABCD and A, or between BBB and J?

Last edited by Don Cragun; 10-17-2015 at 08:13 AM.. Reason: Change PHP tags to CODE tags.
# 6  
Old 10-17-2015
Based on the assumption your file contains only upper case chars and digits, this would yield all separators used:
Code:
awk '{gsub(/[A-Z0-9]/,"");for (i=1; i<=length; i++) C[substr($0,i,1)]++} END {for (c in C) print c}' file

# 7  
Old 10-17-2015
Thank you RudiC. I tried it but the output is nothing, which I dont think is wrong. The answer is there, its just that whether the answer are spaces or tabs, these are not being printed as " " or "t". In other words, for the file

Code:
ABCD    A   L

which is ABCDtabAspacespacespaceL

I would expect awk to print these separators, something like:

Code:
awk_command
output:
t "   "


Last edited by Don Cragun; 10-17-2015 at 08:14 AM.. Reason: Change PHP tags to CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Separation

Hi I have an XML File with default header($ lines of data) and default tail (Two Lines) and the body has occurrence of start<Folder> and ends with </Folder>. Now i want to split each occurrence i mean each start and end in to separate files with header and tail. For example: header line... (12 Replies)
Discussion started by: Nithin Kumar
12 Replies

2. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

3. UNIX for Dummies Questions & Answers

Using awk/sed to determine whether there are any 2's, 3's and 4's in a column

Hi, I have a very large file which is of the general format: 0 3 4 2 ... 3 2 4 0 ... 0 3 4 2 ... 3 0 4 2 ... . . . . ... . . . . ... I would like to apply a simple awk/sed script to work out whether there are any 2's, 3's and 4's in each column. The results would look as... (3 Replies)
Discussion started by: kasan0
3 Replies

4. Shell Programming and Scripting

metacharacters separation

I have prepared a script to submit a string in a txt file. However there are somethings that I have to check before submitting the string in the txt file. One of those checks is to determine whether the string entered contains any metacharacters. I have tried sth like; echo "string" | grep -v ... (3 Replies)
Discussion started by: ozum
3 Replies

5. Shell Programming and Scripting

Format Column

I need a script that takes it input wither it be from a file or inputed as variables and sort that into three columns. Thanks (3 Replies)
Discussion started by: prottheman
3 Replies

6. Shell Programming and Scripting

Help need to write a script on column separation for syslog output in perl

HI Pros, I have a issue.I need to write a script to parse the logs got from syslog server and update the same in my database.I need the following output.I donot know perl and I heard it very easy to write in perl I have the sample log I need each column seperated by commas and all equals... (0 Replies)
Discussion started by: iron_michael86
0 Replies

7. Shell Programming and Scripting

How to format a column

Hi everybody I want to manipulate the output of this command: df -h to something like this: df -h | awk '{print"\t\t "$1"\t\t"$6"\t\t"$2"\t\t" $4}' | sed 's/Mounted/Mount Point/g' | sed 's/Avail/Free Space/g'but my problem is: if for example the mounting point is a long name everything beside... (3 Replies)
Discussion started by: ialbert
3 Replies

8. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

9. Shell Programming and Scripting

Joining three lines with comma separation

I have a file that looks like this: G. KRESSLAR 9618 W. APPALOOSA DRIVE SUN CITY, AZ 85373 SHIRLEY ALLEN 7272 W. VIA MONTOYA DRIVE GLENDALE, AZ 85310 LOUIS VALDEZ 244441 N. 86TH AVENUE PEORIA, AZ 85383 DONNA NEWBON 3231 W. DENTON #D PHOENIX, AZ 85017 SARAH WILSON 6534 W. PALO... (3 Replies)
Discussion started by: BCarlson
3 Replies
Login or Register to Ask a Question