Help with File Processing

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 11-17-2011
Question Help with File Processing

I have a i/p file as
Code:
1234568,abcd,12-13-1898,painting,delayed
23424452,bedsd,14-87-2006,delivery


I have to insert pipe(|) in place of commas. ONLY for first three commas. not after that.

PS: There are so many records in the file like this.


Many Thanks!
# 2  
Old 11-17-2011
3 per row or overall? What have you tried so far?
# 3  
Old 11-17-2011
Only for the first three commas.
If there are any more we have to skip.

What actually is the file have four fields which are comman separated. The fourth filed might encounter commas in some cases.

So we have to change the comma separate to Pipe delimiter.
# 4  
Old 11-17-2011
Your explanation seems confusing to me, but I'll assume you want to replace 3 per line, and not 3 per file:
Code:
sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),/\1|\2|\3|/' infile

# 5  
Old 11-17-2011
MySQL

Quote:
Originally Posted by CarloM
Your explanation seems confusing to me, but I'll assume you want to replace 3 per line, and not 3 per file:
Code:
sed 's/^\([^,]*\),\([^,]*\),\([^,]*\),/\1|\2|\3|/' infile

Worked like charm!!!

Can U explain abt this, for me!
# 6  
Old 11-17-2011
sed 's/x/y/' infile
substitutes the first occurrence of y for x on every line of infile.

Regular expressions:
\(...\) stores the matched text for later.
^ by itself is start of line.
[^,] any character that's not a comma.
* zero or more occurances of the previous regexp.

\1 the text that matched the first bracketed (\(...\) search expression.

Last edited by CarloM; 11-18-2011 at 06:25 AM..

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
File Processing nikhil jain Shell Programming and Scripting 3 03-29-2017 04:37 AM
awk - Rename output file, after processing, same as input file High-T UNIX for Dummies Questions & Answers 12 02-01-2015 09:34 PM
File processing ATWC Shell Programming and Scripting 8 03-09-2014 06:31 AM
awk processing / Shell Script Processing to remove columns text file ajayram Programming 5 03-23-2013 02:51 PM
Recursive file processing from a path and printing output in a file Optimus81 Shell Programming and Scripting 1 12-14-2012 12:55 PM
Help with File processing karumudi7 Shell Programming and Scripting 7 10-10-2011 04:34 PM
File Processing expert Shell Programming and Scripting 2 05-07-2011 01:42 AM
Help in file processing selvam Shell Programming and Scripting 6 04-16-2011 11:25 PM
How to make parallel processing rather than serial processing ?? Samb95 Shell Programming and Scripting 0 08-16-2010 04:56 AM
help with processing a file dsravan Shell Programming and Scripting 4 06-16-2010 02:22 PM
How to processing the log file within certain dates based on the file name shyork2001 Shell Programming and Scripting 1 04-09-2010 11:58 AM
how to change the current file processing to some other random file in awk ? salman4u Shell Programming and Scripting 2 03-02-2009 04:35 AM
Checking for a control file before processing a data file purna.cherukuri Shell Programming and Scripting 4 09-01-2008 11:52 AM
Have a shell script check for a file to exist before processing another file heprox Shell Programming and Scripting 3 11-14-2006 03:26 AM