Sponsored Content
Top Forums Shell Programming and Scripting Insert a value between two empty delimiter in the file. Post 303022699 by RudiC on Wednesday 5th of September 2018 01:06:32 PM
Old 09-05-2018
That would insert \N between every other delimiter pair only, at least on my linux system: ironic theod|\N||\N||\N||\N||\N||\N||\N||\N||\N||\N||\N||\N|


Try an extended version:



Code:
sed 's#||#|\\N|#g; s#||#|\\N|#g; s#|$#|\\N#' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert text between delimiter

Can someone help me on this? I'm creating an Insert stmt script but Oracle does not accept blanks values. How can I insert the word null between two commas? I'm guessing awk or sed. Is there a good post or site with easy to understand info on awk and sed? I'm really new to unix scripts :D ... (5 Replies)
Discussion started by: ystee
5 Replies

2. Shell Programming and Scripting

Awk split doesn't work for empty delimiter

Does anyone know how will I make awk's split work with empty or null separator/delimiter? echo ABCD | awk '{ split($0,arr,""); print arr; }' I need output like: A B C D I am under HP-UX (5 Replies)
Discussion started by: Orbix
5 Replies

3. UNIX for Advanced & Expert Users

Insert Delimiter at fixed locations in a flat file

Hi Can somebody help me with solution for this PLEASE? I have a flat file and need to insert delimiters at fixed positions in all the lines so that I can easily convert into EXCEL with columns defined as per their width. For Example Here is the file { kkjhdhal sdfewss sdtereetyw... (7 Replies)
Discussion started by: jd_mca
7 Replies

4. Shell Programming and Scripting

Sed insert text at first line of empty file

I can't seem to get sed to allow me to insert text in the first line of an empty file. I have a file.txt that is a 0 byte file. I want sed to insert " fooBar" onto the first line. I've tried a few options and nothing seems to work. They work just fine if there's text in the file tho. Help? (4 Replies)
Discussion started by: DC Slick
4 Replies

5. Shell Programming and Scripting

insert delimiter

I have a data file that I would like to add delimiters to. Example: Turn This: 20110624000744000693000704000764 Into This: 20110624,000744,000693,000704,000764 I found this link but the only issue is I do not know how many colums I will have. The first field would needs to be 8... (9 Replies)
Discussion started by: oldman2
9 Replies

6. Shell Programming and Scripting

insert text into empty file

I have an awk script to extract data from several files and create output in the following format as a csv file: xxxx 01/04/12 0001 0 When data is present, I have a file. When no data is available in the input files, I would still like to create a file that looks like this: xxxx... (1 Reply)
Discussion started by: banjo25
1 Replies

7. Shell Programming and Scripting

Insert empty columns in a flat file

Hi, I have a tab delimited flat file, for example shown below Name Desg Loc a b c d e fI want to insert an empty column inbetween the column Desc and Loc, the result should be like shown below: Name LName Desg Loc a b c d e ... (6 Replies)
Discussion started by: sampoorna
6 Replies

8. UNIX for Dummies Questions & Answers

Insert row into empty file...how?

Greetings: I generate an empty flat file just fine when there's no data returned from my process, as the customer wants one always (using the 1st line of the below script). However, they also want at least the column names in this flat file (row 1, the only row to be in the emply file). I'm... (7 Replies)
Discussion started by: Benrosa
7 Replies

9. Shell Programming and Scripting

[Solved] Insert tabs as delimiter

Hello all, I have an unstructured file with space as delimiter , which I want to structure. The output file should actually have only 5 columns with tab as delimiter. The 4th column can have only 3 values ( biological_process , cellular_component , molecular_function ) Here is how the... (12 Replies)
Discussion started by: ritakadm
12 Replies

10. Shell Programming and Scripting

Insert empty columns inside a pipe delimited file

Hi All , I have pipe delimiter file with 11 columns . I need to insert 4 empty columns after column 10 . and After 11 column I need to insert a column which is having the same value for all the rows . My file 1|2|3|4|5|6|7|8|9|10|11 New file ... (11 Replies)
Discussion started by: Hypesslearner
11 Replies
STRSEP(3)						   BSD Library Functions Manual 						 STRSEP(3)

NAME
strsep, stresep -- separate strings LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strsep(char **stringp, const char *delim); char * stresep(char **stringp, const char *delim, int escape); DESCRIPTION
The strsep() function locates, in the nul-terminated string referenced by *stringp, the first occurrence of any character in the string delim (or the terminating '' character) and replaces it with a ''. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *stringp. The original value of *stringp is returned. An ``empty'' field, i.e., one caused by two adjacent delimiter characters, can be detected by comparing the location referenced by the pointer returned by strsep() to ''. If *stringp is initially NULL, strsep() returns NULL. The stresep() function also takes an escape character that allows quoting the delim- iter character so that it can be part of the source string. EXAMPLES
The following uses strsep() to parse a string, containing tokens delimited by white space, into an argument vector: char **ap, *argv[10], *inputstring; for (ap = argv; ap < &argv[9] && (*ap = strsep(&inputstring, " ")) != NULL;) { if (**ap != '') ap++; } HISTORY
The strsep() function is intended as a replacement for the strtok() function. While the strtok() function should be preferred for portabil- ity reasons (it conforms to ANSI X3.159-1989 (``ANSI C89'')) it is unable to handle empty fields, i.e., detect fields delimited by two adja- cent delimiter characters, or to be used for more than a single string at a time. The strsep() function first appeared in 4.4BSD. BSD
August 12, 2006 BSD
All times are GMT -4. The time now is 06:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy