Sponsored Content
Top Forums Shell Programming and Scripting Minimum whitespace separated CSV file generation Post 302310652 by devtakh on Sunday 26th of April 2009 07:02:01 AM
Old 04-26-2009
Quote:
Originally Posted by vharsha
hi tyler, thanks a lot for your quick reply. The script works well but the only problem is that it doesn't take into account the blank fields. These blank fields are ignored in the output and the immediate populated field gets displayed. For e.g;

Input

D BRUX EXCC CC||JLCSVD|1|VIC|
T BGNW BSAT SA|||7|VIC|
T PNTO SCTC E0|NGS PK B/B|JLCNSD||NSW|
P GLSE P4BR Z5||||NSW|
P GLSE P4BR Z5|PK B/B NON AUG|JLCQLD|30||
D DANB EXCC CC|OTHER|JLCSVD|1|VIC|
T PNTO SPTG E0|NGS PK B/B|JLCNSD|3|NSW|

Output

"D BRUX EXCC CC" JLCSVD 1 VIC
"T BGNW BSAT SA" 7 VIC
"T PNTO SCTC E0" "NGS PK B/B" JLCNSD NSW
"P GLSE P4BR Z5" NSW
"P GLSE P4BR Z5" "PK B/B NON AUG" JLCQLD 30
"D DANB EXCC CC" OTHER JLCSVD 1 VIC
"T PNTO SPTG E0" "NGS PK B/B" JLCNSD 3 NSW

Ideal output should have been

"D BRUX EXCC CC" JLCSVD 1 VIC (3 blank characters)
"T BGNW BSAT SA" 7 VIC (6 blank characters)
"T PNTO SCTC E0" "NGS PK B/B" JLCNSD NSW (3 blanks again)
"P GLSE P4BR Z5" NSW (9 blank characters)
"P GLSE P4BR Z5" "PK B/B NON AUG" JLCQLD 30
"D DANB EXCC CC" OTHER JLCSVD 1 VIC
"T PNTO SPTG E0" "NGS PK B/B" JLCNSD 3 NSW

Is there a way to address this also in your script. Thanks again for ur inputs.

ldapswandog- thanks to u as well for ur inputs.

try this in awk:

$ awk -F "|" '{
for (i=1;i<=NF;i++) {
if ( $i == "") printf (" ");
if (split($i,t," ") > 1)printf(" \"%s\"",$i)
else printf(" %s", $i)
}printf "\n"
}' filename


cheers,
Devaraj Takhellambam
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

rename file with whitespace embedded

Say a directory contains files 1) "file name 1.xxx" 2) "file name2.yyy" 3) etc Using a cshell script, is there a way to (1)search for all files that contain " " in the filename and then (2)rename the files so that you replace the whiitespace " " with a "_". First problem I run into is... (6 Replies)
Discussion started by: orlando47
6 Replies

2. Shell Programming and Scripting

removing whitespace from middle of file -help

I have a file in which I clean out a bunch of nonsense text as well as path information. What I end up with is something like the following: johnson.........................................................933 Where the periods represent the whitespace The file comes out originally with... (2 Replies)
Discussion started by: roninuta
2 Replies

3. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

4. UNIX for Dummies Questions & Answers

Getting the minimum of each column in a file

Hi, I have a file like: 0.000000 124.085533 124.085533 124.085533 124.085533 124.085533 124.085533 124.085533 124.085533 124.085533 33.097845 33.363764 0.000000 266.483441 262.519130 266.380993 274.989622 289.594799 309.523518 336.124848 372.386124 413.522043 429.984825 421.621810... (6 Replies)
Discussion started by: cosmologist
6 Replies

5. Shell Programming and Scripting

Text file to CSV with field data separated by blank lines

Hello, I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies

6. Shell Programming and Scripting

How to redirect in comma separated csv from grep

Hi, I am newbie in unix. Could someone tell me how do I redirect my grep output to a csv/excel ? I have used below command but the outputs are appearing in one column Not in different column. grep -e cmd -e cmd1 test.txt | cut -f 5 | sort | uniq -c> op.csv I do not understand how do I... (14 Replies)
Discussion started by: kmajumder
14 Replies

7. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

8. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

9. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies
ISBLANK(3)						   BSD Library Functions Manual 						ISBLANK(3)

NAME
isblank -- blank-space character test LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ctype.h> int isblank(int c); DESCRIPTION
The isblank() function tests for the standard blank-space characters. The standard blank-space characters are the following: ' ' Space character. Horizontal tab. In the ``C'' locale, isblank() returns true only for the standard blank-space characters. RETURN VALUES
The isblank() function returns zero if the character tests false and returns non-zero if the character tests true. SEE ALSO
ctype(3), isalnum(3), isalpha(3), isascii(3), iscntrl(3), isdigit(3), isgraph(3), islower(3), isprint(3), ispunct(3), isspace(3), isupper(3), isxdigit(3), stdio(3), toascii(3), tolower(3), toupper(3), ascii(7) CAVEATS
The argument to isblank() must be EOF or representable as an unsigned char; otherwise, the behavior is undefined. See the CAVEATS section of ctype(3) for more details. BSD
April 17, 2008 BSD
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy