Sponsored Content
Full Discussion: Replace the | with Comma
Top Forums Shell Programming and Scripting Replace the | with Comma Post 302470642 by bharathappriyan on Wednesday 10th of November 2010 05:11:09 PM
Old 11-10-2010
Replace the | with Comma

Hi,

The input file structure is given below: The Col1 and Col2 will be there always. But from Col3 there can be more columns.
And Col3 will be always Col4 and Col5 will always be with Col6. I need to replace the | with comma. There are scnearios where there
wont be no data.Below, the row 2 does not have data for col5,col6,col6,col8. I am using the command
Code:
cat Testin1|sed -e 's/||/,,,/g' -e 's/|/,/g'

How i use this command to achieve my requirement Or what is the best way to handle this?

Input:
Code:
Col1,Col2|Col3,Col4|Col5,Col6|Col7,Col8
Market1,"Chain1"|3,3|3,3|3,3|3,3
Market1,"Chain1"|3,3|||
Market1,"Chain1"||3,3||
Market1,"Chain1"|||3,3|
Market1,"Chain1"||||3,3

Expected Output:
Code:
Market1,"Chain1",3,3,3,3,3,3,3,3
Market1,"Chain1",3,3,,,,,,,
Market1,"Chain1",,,3,3,,,,,
Market1,"Chain1",,,,,3,3,,,
Market1,"Chain1",,,,,,,3,3

Current Output:
Code:
Market1,"Chain1",3,3,3,3,3,3,3,3
Market1,"Chain1",3,3,,,,
Market1,"Chain1",,,3,3,,,
Market1,"Chain1",,,,3,3,
Market1,"Chain1",,,,,,3,3

Thanks,
bharathappriyan

Last edited by Scott; 11-10-2010 at 06:18 PM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace , (comma) with space

Hi, what is the better way to replace the , (comma) with a space char? Example:STRING=dir1,dir2,dir3 toSTRING=dir1 dir2 dir3 And.. how to find if in the string there is a comma? Thanks :) (6 Replies)
Discussion started by: mbarberis
6 Replies

2. Shell Programming and Scripting

replace comma(,) with Tab

hi all, i have a file with commas(,). i want to replace all the commas with tab(\t). Plz help...its urgent... (3 Replies)
Discussion started by: vikas_kesarwani
3 Replies

3. Shell Programming and Scripting

Replace comma with newline

Hi, for some reason I cant seem to figure this out. I have a file which looks something like this word word word word word,word,word word word word,word,word,word,word word word Basically I want this whole thing to be a list with 1 word on each line like this... word word word... (1 Reply)
Discussion started by: eltinator
1 Replies

4. Shell Programming and Scripting

replace space with comma in perl

arr_Ent_NameId variable holds 'Prakash pawar' 'sag' '23' '50000' this value 'Prakash pawar' 'sag' '23' '50000' I want to replace space( ) with comma (,) There are 4 fields here. I don't want to replace first field with comma. output should be: 'Prakash,pawar','sag','23','50000' ... (2 Replies)
Discussion started by: pritish.sas
2 Replies

5. Shell Programming and Scripting

Replace newline with comma.

I have output from a file like this: 15,01,11,14:06 235 I would like to change this to: 15,01,11,14:06,235 Removing newline and change to "," I now this can be done with tr cat OUT | tr '\n' ','' My problem is that tr is not implemented in this shell. sed is, show it should be... (7 Replies)
Discussion started by: Jotne
7 Replies

6. Shell Programming and Scripting

Replace pipe <|> with comma <,> in a column

Hi All Gurus, I need to replace a pipe <|> with a comma <,> in a few columns with pipe delimited file. The column name are fixed for the replacement of comma <,>. For below example, Col3, Col6 and Col8 are columns need to replace with comma <,> if any pipe encountered. example:... (14 Replies)
Discussion started by: agathaeleanor
14 Replies

7. UNIX for Dummies Questions & Answers

How to replace two or more spaces with one comma?

I'm using sh on hp-ux. I've got a file that looks like this. -5.65 175 -16.17 160 -13.57 270 -51.72 260 -8.30 360 -42.71 460 -.38 375 -.20 375 -4.15 170 -21.53 560 -18.84 360 I'd like to replace all the whitespace between the columns with one comma. I can't... (4 Replies)
Discussion started by: Scottie1954
4 Replies

8. Shell Programming and Scripting

Command to replace newline with comma

Hi Experts, I need an urgent help in replacing newline characters in my single column file by a comma. I am using following command for this purpose: sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' parameter.rtf | rev | cut -c 4- | revMy input file has: TABLE_1 TABLE_2 TABLE_3 What I need:... (11 Replies)
Discussion started by: neerndg123
11 Replies

9. Shell Programming and Scripting

Replace comma and blank with comma and number

I, I have a file and i need to replace comma and blank space with comma and 0. cat file.txt a,5 b,1 c, d, e,4 I need the output as cat file.txt a,5 b,1 c,0 d,0 (4 Replies)
Discussion started by: jaituteja
4 Replies

10. Shell Programming and Scripting

Replace spaces with underscores up to first comma but not after the comma

I have a comma delimited file of major codes and descriptions. I want to replace all occurrences of spaces with underscores up to the first comma (only in the first field), but not replace spaces following the comma. For instance I have the following snippet of the file: EK ED,Elementary and... (7 Replies)
Discussion started by: tdouty
7 Replies
SLUGIMAGE(1)						      General Commands Manual						      SLUGIMAGE(1)

NAME
slugimage - Manipulate NSLU2 firmware images SYNOPSIS
slugimage [-p|-u] [options] DESCRIPTION
slugimage can be used to create or unpack NSLU2 firmware images. OPTIONS
-d, --debug Turn on debugging output -q, --quiet Turn off status messages -u, --unpack Unpack a firmware image -p, --pack Pack a firmware image -l, --little Convert Kernel and Ramdisk to little-endian -i, --input Input firmware image filename -o, --output Output firmware image filename -b, --redboot Input/Output RedBoot filename -k, --kernel Input/Ouptut Kernel filename -s, --sysconf Input/Output SysConf filename -r, --ramdisk Input/Output Ramdisk filename(s) -f, --fisdir Input/Output FIS directory filename -y, --payload Input/Output Payload filename -t, --trailer Input/Output Trailer filename -e, --ethaddr Set the Ethernet address AUTHOR
This man page was written by Joey Hess, <joey@kitenet.net>. SLUGIMAGE(1)
All times are GMT -4. The time now is 03:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy