Insert a value between two empty delimiter in the file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert a value between two empty delimiter in the file.
# 1  
Old 09-05-2018
Insert a value between two empty delimiter in the file.

Would like to insert value between two empty delimiter and at the very last too if empty.

Code:
$ cat customerleft.tbl
300|Customer#000000300|I0fJfo60DRqQ|7|17-165-193-5964|8084.92|\N|p fluffily among the slyly express grouches. furiously express instruct||||||||||||||||||||||||\N
297|Customer#000000297|hzg,409pj0|15|25-915-518-8800|7096.32|HOUSEHOLD|de of the regular asymptotes detect slyly ironic theod||||||||||||||||||||||||

Output:
Code:
300|Customer#000000300|I0fJfo60DRqQ|7|17-165-193-5964|8084.92|\N|p fluffily among the slyly express grouches. furiously express instruct|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N
297|Customer#000000297|hzg,409pj0|15|25-915-518-8800|7096.32|HOUSEHOLD|de of the regular asymptotes detect slyly ironic theod|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N


I tried using
Code:
sed 's/||/|\\N|/g' customerleft.tbl

but no success! Please assist.
# 2  
Old 09-05-2018
Code:
 sed 's#||#|\\N|#g;s#|$#|\\N#' myFile

# 3  
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

# 4  
Old 09-05-2018
Code:
perl -pe 's/\|(?=\||$)/\|\\N/g' customerleft.tbl
300|Customer#000000300|I0fJfo60DRqQ|7|17-165-193-5964|8084.92|\N|p fluffily among the slyly express grouches. furiously express instruct|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N
297|Customer#000000297|hzg,409pj0|15|25-915-518-8800|7096.32|HOUSEHOLD|de of the regular asymptotes detect slyly ironic theod|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N|\N

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question