Sponsored Content
Top Forums Shell Programming and Scripting Minimum whitespace separated CSV file generation Post 302310550 by vharsha on Saturday 25th of April 2009 02:53:36 PM
Old 04-25-2009
Minimum whitespace separated CSV file generation

Hi,

I have a flat text file consisting of rows (each field separated by '|') from a table. e.g;

NSW|Gulliver Travels|236||5000|BW

This has to be converted to the following format

NSW "Gulliver Travels" 236 5000 BW

No data field has to be left as a blank character so that we have three blank characters in effect between the two consecutive populated fields in the above scenario.

I have actually other flat files also with the same requirement. The no. of fields are different in the other files. So I am in need of a unix script to do this which can be applied directly to all the flat files irrespective of the no. of columns or fields. I have been trying with awk and I accomplished only the following which is not desirable.

NSW Gulliver Travels 236 5000 BW

Also I used hard-coding for this.
Any pointers to solve this are greatly appreciated and would help me a lot.
 

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
firestring_estr_chug(3) 				     Library Functions Manual					   firestring_estr_chug(3)

NAME
firestring_estr_chug - remove whitespace from the beginning of an estring SYNOPSIS
#include <firestring.h> -lfirestring void firestring_estr_chug(struct firestring_estr_t *string) DESCRIPTION
firestring_estr_chug shortens string by moving the start forward until the string begins with a non-whitespace character or is empty. CAVEATS
This function moves the starting pointer inside string. If string was allocated with firestring_estr_alloc(3), (as opposed to constructed manually pointing inside other memory), future calls to firestring_estr_free(3) will fail if this function trimmed any space from the start of the string. In these cases, use firestring_estr_ip_chug(3) instead. RETURN VALUE
None. AUTHOR
Ian Gulliver <ian@penguinhosting.net> SEE ALSO
libfirestring(3) 2003-07-30 firestring_estr_chug(3)
All times are GMT -4. The time now is 06:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy