Removing unnecessary Delimiters from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing unnecessary Delimiters from a file
# 1  
Old 11-18-2009
Removing unnecessary Delimiters from a file

Hi all,

I have a pipe delimited file - (sample data)
Code:
1|1|K|Doe|1234567890|123456789|EXP|99|99|John|Y|Dallas|Texas|Kyle|999
2|1|A|2|01/01/9999|Appl|01/01/9999|vendor|Select||||||
3|1|A|2|01/01/9999|Check|01/01/9999|ksmith|Suggest||||||
4|1|T|Complaint|Mary|01/01/9999|01/01/9999|||||||
5|1|T|File|Steve|01/01/9999|01/01/9999|||||||
1|2|K|Jerry|12|123|EXP|99|99|Smith|Y|Orlando|Florida|Joe|999
2|2|A|2|01/01/9999|Application|01/01/9999|vendor|Select||||||
3|2|A|2|01/01/9999|Check|01/01/9999|ksmith|Suggest||||||
4|2|T|Complaint|Tim|01/01/9999|01/01/9999|||||||
1|3|K|George|12345|12|EXP|99|99|David|Y|Albany|New York|Peter|999
2|3|A|2|01/01/9999|Application|01/01/9999|vendor|Select||||||
3|3|T|Complaint for a MEPD Case|Doe,Mary|01/01/9999|01/01/9999|||||||

I need to get rid of these unnecessary "|" delimiters from rows where third field in not 'K'. e.g. The "|" after Select & Suggest in line 2 and 3.

Thanks
Sumeet

Last edited by radoulov; 11-18-2009 at 11:48 AM.. Reason: Please use code tags.
# 2  
Old 11-18-2009
Code:
sed s'/|*$//' infile

# 3  
Old 11-18-2009
Thanks
Sumeet
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

Shell script that should remove unnecessary commas between double quotes in CSV file

i have data as below 123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi" i need an output to be 123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Discussion started by: mathias23
5 Replies

3. UNIX for Dummies Questions & Answers

Removing unnecessary eol ($) character from Oracle sql query output

Hi All, I am fetching oracle query result in shell variable. As columns numbers are more the output wraps in unix terminal .i.e one complete record in db gets store in multiple lines. with each line ends with $ character. I want to remove these unnecessary $ character but to keep required $... (8 Replies)
Discussion started by: Harshal22
8 Replies

4. Solaris

to clean unnecessary files and folders

I want to clean used solaris OS and then to give another developer. How can I understand that difference between system file/folder and others. I want to delete apart from the files/folders. I need tools or scripts like disk-cleanup or something like that. #usr>du -s -h * 6.6M 4lib ... (1 Reply)
Discussion started by: getrue
1 Replies

5. Shell Programming and Scripting

How to fix file with more delimiters

Hi, gunius I have a post as following I use one of posted code resolved. code following. awk -F\, 'NF==5{$3=$3""$4;$4="";sub(/,,/,",")}1' OFS="," infile I got new problem, my file contains some null column, target should be 126,,shepperd street 203#, 23459 using current code, I got ... (4 Replies)
Discussion started by: ken002
4 Replies

6. UNIX for Advanced & Expert Users

remove unnecessary comma from file

HI all, I have a file with following data - test1 "ABC,D",1234,"XYZ,QWER",1234 "SZXA",9870,"ASD,QWERT",234 "XZ,SD",9478,"ADCS,AXZ",876 "WESR",8764,"AQZXAS",9888 "WESR",9898,"WESDRTSAW",3323 I need to get rid of unnecessary commas in fields having double quotes. Ouput - ... (1 Reply)
Discussion started by: sumeet
1 Replies

7. UNIX for Dummies Questions & Answers

How to count number of delimiters in a file name

I have a list of files with names as "FULL_abcd_xyz_timestamp.txt" and "FULL_xx_abcd_xyz_timestamp.txt". I am writing a script with a 'for loop' to take each file, strip the "FULL" and "timestamp" from the file name and do some actions on the contains of the file. So I need to know the number of... (4 Replies)
Discussion started by: ayanbiswas
4 Replies

8. UNIX for Dummies Questions & Answers

How do I insert commas/delimiters in File

Hi, Newbie here. Need to convert a txt file to .csv format. There's no character to replace so not sure if I can use sed :confused: . The comma is to be inserted after every certain number of characters in each line... Help! Thanks. (4 Replies)
Discussion started by: mbelen
4 Replies

9. IP Networking

unnecessary route entry?

Good day :) I recently checked some stuff on my gateway and discovered what I believe is an unneeded route entry. # route -n Kernel IP routing table Destination Gateway Genmask ... Iface 287.265.45.0 0.0.0.0 255.255.255.0 ... eth0 192.168.0.0 0.0.0.0 ... (3 Replies)
Discussion started by: J.P
3 Replies

10. UNIX for Dummies Questions & Answers

remove unnecessary lines

If I have a file with 5000 lines contains numbers. Some of the number are repeated and some are not. Among those repeated number, I only would like to keep only one. How do I remove those balance repeated number. Your help is much appreciated. Thank you. (3 Replies)
Discussion started by: nazri
3 Replies
Login or Register to Ask a Question