06-21-2008
i need to add missing delimiters...
ladies, gents..
say i have a file that should have 10 fields... (9 delimiters)
some records have 10 fields, some have 5 some have 8, etc.. nothing consistent, but i need my file to have 9 delimiters on each line, even if its null fields..
how can i go line by line and add the correct # of delimiters if they are missing..
i have a dirty way... but looking for help on a more elegant solution...
thanks
my ugly way... works fine on small stuff.. but when you have 100's of files, ranging in size from 10 -200 fields.. its just not practical
this example... i expect 4 delimiters on each line...
(i dont need to substitute the delimiters, just used the 1's for ease of reading)
$ cat test.txt
a1b1c1
a1b
a1b1c1
cat test.txt | awk -F1 '{print $1 "|" $2 "|" $3 "|" $4}'
a|b|c|
a|b||
a|b|c|
thanks in advance..
ob
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have a pipe-delimited file where I eventually need to replace a string stored on the 3th field on a specific record.
This is how the file looks like:
A|Mike|Lvl 1|...
B|...
A|Maria|Lvl 1|...
C|...
B|...
A|Jimmy|Lvl 2|...
C|...
A|Carry|Lvl 0|...
C|...
B|...
A|John|Lvl 8|...... (2 Replies)
Discussion started by: Indalecio
2 Replies
2. Shell Programming and Scripting
Not sure about the title if someone has a better name for it please lemme know and I will edit the title.
I have several (10+ files) which look something like:
File 1:
12/28/2009 04:0 8
12/28/2009 04:4 4
12/28/2009 05:0 4
.
.
.
File 2:
12/28/2009 04:1 7
12/28/2009 04:2 3... (2 Replies)
Discussion started by: jstrangfeld
2 Replies
3. UNIX and Linux Applications
Hi,
Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3.
Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file
~Thanks
Step-1: Execute command
> mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Discussion started by: newbielgn
3 Replies
4. Shell Programming and Scripting
I need to take a report text file that is output from vendor software and there are some pages which have less then the normal amount of lines. I need to add these missing line feeds as there is a merge program that reads this file in fixed character and line mode template to output the final PDF... (6 Replies)
Discussion started by: rnygren
6 Replies
5. UNIX Desktop Questions & Answers
hello all,
I have files that have a specific way for naming the first column
they are make of five names in Pattern of 3
Y = (no case sensitive)
so the files are names $Y-$Y-$Y or $X-$Y-$Z depending how we look
they only exist of the pattern exist
now I want to create a file from them that... (9 Replies)
Discussion started by: A-V
9 Replies
6. Solaris
Issue resolved by upgrading from solaris 11 to solaris 11.1
I would like to enable network mapping.
While using instructions from:
https://blogs.oracle.com/VDIpier/entry/solaris_11_changing_the_hostname
To change my hostname I noticed I am missing the enable mapping bool.
What it should... (0 Replies)
Discussion started by: taltamir
0 Replies
7. Red Hat
I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following:
sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm
Loaded plugins: fastestmirror
Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies
8. Shell Programming and Scripting
Hi Gurus,
I have a txt file. some record missed 2nd colum value, I need put default value into the file.
ex: below file, first 4 records, missed one column (only 4 columns. it should be 5)
$cat missedfield
aaa,bbb,ccc,fff
aaa,bbb,ccc,ddd
111,222,333,444
111,222,333,444... (3 Replies)
Discussion started by: ken6503
3 Replies
9. Shell Programming and Scripting
Hi team...
I need some help/advise on adding a word for a missing column.
I have a file as below.
Rep N1
Forever
Limited
2015
Rep N2
Limited
2016
since 2nd content is 3 lines missing one line so i need to make this like
Rep N1
Forever (3 Replies)
Discussion started by: newbee5
3 Replies
10. Shell Programming and Scripting
Hi Again,
I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file.
INPUT
2016-01-13 01:33 10
2016-01-13 01:31 10
2016-01-13 01:30 10
2016-01-13 01:29 10
2016-01-13 01:28 10
2016-01-13 01:27 10
2016-01-13 01:26 10
2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies
LEARN ABOUT LINUX
bufsplit
bufsplit(3GEN) String Pattern-Matching Library Functions bufsplit(3GEN)
NAME
bufsplit - split buffer into fields
SYNOPSIS
cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
size_t bufsplit(char *buf, size_t n, char **a);
DESCRIPTION
bufsplit() examines the buffer, buf, and assigns values to the pointer array, a, so that the pointers point to the first n fields in buf
that are delimited by TABs or NEWLINEs.
To change the characters used to separate fields, call bufsplit() with buf pointing to the string of characters, and n and a set to zero.
For example, to use colon (:), period (.), and comma (,), as separators along with TAB and
NEWLINE:
bufsplit (":.,
", 0, (char**)0 );
RETURN VALUES
The number of fields assigned in the array a. If buf is zero, the return value is zero and the array is unchanged. Otherwise the value is
at least one. The remainder of the elements in the array are assigned the address of the null byte at the end of the buffer.
EXAMPLES
Example 1: Example of bufsplit() function.
/*
* set a[0] = "This", a[1] = "is", a[2] = "a",
* a[3] = "test"
*/
bufsplit("This is a test
", 4, a);
NOTES
bufsplit() changes the delimiters to null bytes in buf.
When compiling multithreaded applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in mul-
tithreaded applications.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO
attributes(5)
SunOS 5.10 29 Dec 1996 bufsplit(3GEN)