replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace
# 1  
Old 04-07-2008
replace

hi
i have input file in this format
E102|0|1-23-1994|0|12-5-1994|E003|A|10450|charan,devupalli|5000

how to convert this into outfile
E102,0,1-23-1994,0,12-5-1994,E003,A,10450,charan,devupalli,5000

i wann the output in excel sheet.........that is why i am converting into csv..
but i have the name file as firstname, lastname and it should be present in one column charan,devupalli

Pls send me asap.


thanks in advance
cherry
# 2  
Old 04-07-2008
hi

$ cat > in6
E102|0|1-23-1994|0|12-5-1994|E003|A|charan,devupalli|2000
$ sed 's/|/,/g' in6 > out6.csv
$ cat out6.csv
E102,0,1-23-1994,0,12-5-1994,E003,A,charan,devupalli,2000
in the excel


in the excel i am getting charan and devupalli into two columns but i need to get in a single column like
charan,devupalli.....

thanks
cherry
# 3  
Old 04-07-2008
I'm not certain I'm following what you're saying, but if I do...

Code:
cat in|tr "|" "," > out

should give you what you want. I don't think I understand why your SED statement isn't working, but tr will replace the |'s with ,'s
# 4  
Old 04-07-2008
hi

Quote:
Originally Posted by DeCoTwc
I'm not certain I'm following what you're saying, but if I do...

Code:
cat in|tr "|" "," > out

should give you what you want. I don't think I understand why your SED statement isn't working, but tr will replace the |'s with ,'s
i am getting the date in the excel sheet.

If i have a file like
E001|0|23/01/2007|CHARAN,DEVUPALLI|4000|INDIA| !INPUT

E001,0,23/01/2007,CHARAN,DEVUPALLI,4000,INDIA| !OUTPUT

I CAN CONVERT THE FILE BY USING SED......AND I AM GETTING THE OUT PUT.........
BUT I AM GETTING THE CHARAN IN ONE SEPARATE COLUMN AND THE DEVUPALLI IN SEPARATE COLUMN.

I NEED TO GET THE CHARAN,DEVUPALLI IN A SINGLE COULMN........HOW TO DO THAT........

PLS send how to do that
# 5  
Old 04-07-2008
Code:
echo 'E102|0|1-23-1994|0|12-5-1994|E003|A|10450|charan,devupalli|5000'| sed 's/\([^|][^|]*\)|/"\1",/g'

# 6  
Old 04-07-2008
dude, first, lose the caps.

second, I think your problem lies with the way u handle Excel, not in Unix. If you convert all "|" to commas, the comma becomes a delimiter and "charan,devupalli" become two seperate items, delimited by commas.

A csv file does not need to have comma as a delimiter, you can set the pipe sign as a delimiter too (Use the Tools-> Text to columns and you can set the delimiter there)

So you can use the very first line directly in excel, no need to mod it in unix. you're just going circles.
# 7  
Old 04-07-2008
If you actually want to convert the separator to comma for unrelated reasons, you can have comma inside a field by putting it in double quotes. Different (per)versions of Excel have different bugs and conventions for how exactly they break when you try to do this, so you will have to experiment a bit.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

2. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

3. Shell Programming and Scripting

Replace dashes positions 351-357 & 024-043 with 0 & replace " " if exis with 04 at position 381-382

I need to replace dashes (i.e. -) if present from positions 351-357 with zero (i.e. 0), I also need to replace dash (i.e “-“) if present between position 024-043 with zero (i.e. 0) & I replace " " (i.e. 2 space characters) if present at position 381-382 with "04". Total length of record is 413.... (11 Replies)
Discussion started by: lancesunny
11 Replies

4. Shell Programming and Scripting

How to replace

Here is my file content age=12 age=34 age=54 age=23 Hello world. This is the age result I am getting. To day date is 23-02-2010. From the above content I have to replace all the values after 'age=*' to age=24. How to do it. (1 Reply)
Discussion started by: brahma
1 Replies

5. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

6. Shell Programming and Scripting

Replace Help

Hi, djfksdjk)))) kmmm jfdfjk)))) I want to replace the first ')' after kmmm with #. The output would be djfksdjk)))) exists jfdfjk#))) Can anyone help on this? (3 Replies)
Discussion started by: javeed7
3 Replies

7. Shell Programming and Scripting

replace last / by |

Hi: I want to write a Kshell script which will replace last / by |. eg: /home/apps/test/document should be replaced as /home/apps/test|document. The length of the string is not constant. Thanks, Ash (6 Replies)
Discussion started by: naikaa
6 Replies

8. Shell Programming and Scripting

How to replace into Vi

Ravi . Pawan 19.23 sanjeeva . I want to replace '.' into 'NULL' not the dot between 19.23 .. only single dots to NULL how to do replacement after opening file in Vi (5 Replies)
Discussion started by: ravi.sadani19
5 Replies

9. UNIX for Dummies Questions & Answers

How to replace ??

Hi all, I have a file with the following data. E01011U, ,E11, , , ,0 E03012U, ,E14, , , ,0 E02013U, ,E25, , , ,0 I want to change it to ('E01-01-1-U','E11' ); ('E03-01-2-U','E14' ); ('E02-01-3-U','E25' ); Please let me know about it .Thanks in advance. (10 Replies)
Discussion started by: preethgideon
10 Replies

10. Shell Programming and Scripting

Replace \n with \r\n

Hi Dudes, I want to replace \n with \r\n through out the file. For this I opened vi editor there tried with " s/\\n/\\r\\n/g ", with this I must be able to satisfy my requirements. But it is searching for the current line (Where cursor is). I need this for entire file. No problem if it is... (3 Replies)
Discussion started by: Chanakya.m
3 Replies
Login or Register to Ask a Question