Auto correct a csv file using UNIX shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto correct a csv file using UNIX shell script.
# 36  
Old 02-19-2014
If Scrutinizer's latest suggestion (in message #35) doesn't work, please show us:
  1. the exact contents of your shell script,
  2. the exact command line you use to invoke that shell script,
  3. the output from the command uname -a,
  4. the output from od -c YourShellScript, and
  5. save the output from your shell script in a file and show us the output from od -c OutputFile.
# 37  
Old 02-19-2014
Using builtins only on OSX 10.7.5 default shell...

There may well be a much better method using builtins but this works
and is a starting point.

I appended "sample.txt" 3 times with a newline between each append.

This code removes "\r" as well...
Code:
#!/bin/sh
# csv_text.sh
ifs_str="$IFS"
IFS=""
comma=0
n=0
newtext=""
echo ""
cat sample.txt
echo "Start the corrections..."
echo ""
read -d '' -r text < sample.txt
# Start of conversion...
while true
do
	if [ "${text:$n:1}" == "," ]
	then
		comma=$[ ( $comma + 1 ) ]
		if [ $comma -eq 11 ]
		then
			newtext=$newtext${text:$n:2}$'\n'
			n=$[ ( $n + 2 ) ]
			comma=0
		fi
	fi
	if [ "${text:$n:2}" == $'\r\n' ] && [ $comma -lt 11 ]
	then
		n=$[ ( $n + 2 ) ]
	else
		newtext=$newtext${text:$n:1}
		n=$[ ( $n + 1 ) ]
	fi
	if [ $n -gt ${#text} ]
	then
		break
	fi
done
# End of conversion...
IFS="$ifs_str"
printf "$newtext"
printf "$newtext" > /tmp/sample.txt
hexdump -C < /tmp/sample.txt
exit 0

Results:-
Code:
Last login: Wed Feb 19 20:51:09 on ttys000
AMIGA:barrywalker~> ./csv_test.sh

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202
,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202
,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202
,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

Start the corrections...

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

abcd,789756,20140211,20140202,464532.00,C,XZY,,,Settlement of purchase.,,1
abcd,795156,20140211,20140202,548962.52,C,JPY,,,Payement to: tokyo BNF=N,,1
abcd,763256,20140211,20140202,42188.80,C,USD,,,recieved from ,,1
abcd,756556,20140211,20140202,456898.28,C,EUR,,,Payment via.,,1
abcd,732656,20140211,20140202,58461.10,C,INR,,,Settlement of purchase.,,1
abcd,798756,20140211,20140202,323156.82,C,AUD,,,Settlement of purchase.,,1
abcd,789856,20140211,20140202,84621.63,C,CHF,,,Settlement of sale no B35453 EUR 471.60,,1
abcd,785456,20140211,20140202,86421.40,C,USD,,,Settlement of purchase.,,1

00000000  61 62 63 64 2c 37 38 39  37 35 36 2c 32 30 31 34  |abcd,789756,2014|
00000010  30 32 31 31 2c 32 30 31  34 30 32 30 32 2c 34 36  |0211,20140202,46|
00000020  34 35 33 32 2e 30 30 2c  43 2c 58 5a 59 2c 2c 2c  |4532.00,C,XZY,,,|
00000030  53 65 74 74 6c 65 6d 65  6e 74 20 6f 66 20 70 75  |Settlement of pu|
00000040  72 63 68 61 73 65 2e 2c  2c 31 0a 61 62 63 64 2c  |rchase.,,1.abcd,|
00000050  37 39 35 31 35 36 2c 32  30 31 34 30 32 31 31 2c  |795156,20140211,|
00000060  32 30 31 34 30 32 30 32  2c 35 34 38 39 36 32 2e  |20140202,548962.|
00000070  35 32 2c 43 2c 4a 50 59  2c 2c 2c 50 61 79 65 6d  |52,C,JPY,,,Payem|
00000080  65 6e 74 20 74 6f 3a 20  74 6f 6b 79 6f 20 42 4e  |ent to: tokyo BN|
00000090  46 3d 4e 2c 2c 31 0a 61  62 63 64 2c 37 36 33 32  |F=N,,1.abcd,7632|
000000a0  35 36 2c 32 30 31 34 30  32 31 31 2c 32 30 31 34  |56,20140211,2014|
000000b0  30 32 30 32 2c 34 32 31  38 38 2e 38 30 2c 43 2c  |0202,42188.80,C,|
000000c0  55 53 44 2c 2c 2c 72 65  63 69 65 76 65 64 20 66  |USD,,,recieved f|
000000d0  72 6f 6d 20 2c 2c 31 0a  61 62 63 64 2c 37 35 36  |rom ,,1.abcd,756|
000000e0  35 35 36 2c 32 30 31 34  30 32 31 31 2c 32 30 31  |556,20140211,201|
000000f0  34 30 32 30 32 2c 34 35  36 38 39 38 2e 32 38 2c  |40202,456898.28,|
00000100  43 2c 45 55 52 2c 2c 2c  50 61 79 6d 65 6e 74 20  |C,EUR,,,Payment |
00000110  76 69 61 2e 2c 2c 31 0a  61 62 63 64 2c 37 33 32  |via.,,1.abcd,732|
00000120  36 35 36 2c 32 30 31 34  30 32 31 31 2c 32 30 31  |656,20140211,201|
00000130  34 30 32 30 32 2c 35 38  34 36 31 2e 31 30 2c 43  |40202,58461.10,C|
00000140  2c 49 4e 52 2c 2c 2c 53  65 74 74 6c 65 6d 65 6e  |,INR,,,Settlemen|
00000150  74 20 6f 66 20 70 75 72  63 68 61 73 65 2e 2c 2c  |t of purchase.,,|
00000160  31 0a 61 62 63 64 2c 37  39 38 37 35 36 2c 32 30  |1.abcd,798756,20|
00000170  31 34 30 32 31 31 2c 32  30 31 34 30 32 30 32 2c  |140211,20140202,|
00000180  33 32 33 31 35 36 2e 38  32 2c 43 2c 41 55 44 2c  |323156.82,C,AUD,|
00000190  2c 2c 53 65 74 74 6c 65  6d 65 6e 74 20 6f 66 20  |,,Settlement of |
000001a0  70 75 72 63 68 61 73 65  2e 2c 2c 31 0a 61 62 63  |purchase.,,1.abc|
000001b0  64 2c 37 38 39 38 35 36  2c 32 30 31 34 30 32 31  |d,789856,2014021|
000001c0  31 2c 32 30 31 34 30 32  30 32 2c 38 34 36 32 31  |1,20140202,84621|
000001d0  2e 36 33 2c 43 2c 43 48  46 2c 2c 2c 53 65 74 74  |.63,C,CHF,,,Sett|
000001e0  6c 65 6d 65 6e 74 20 6f  66 20 73 61 6c 65 20 6e  |lement of sale n|
000001f0  6f 20 42 33 35 34 35 33  20 45 55 52 20 34 37 31  |o B35453 EUR 471|
00000200  2e 36 30 2c 2c 31 0a 61  62 63 64 2c 37 38 35 34  |.60,,1.abcd,7854|
00000210  35 36 2c 32 30 31 34 30  32 31 31 2c 32 30 31 34  |56,20140211,2014|
00000220  30 32 30 32 2c 38 36 34  32 31 2e 34 30 2c 43 2c  |0202,86421.40,C,|
00000230  55 53 44 2c 2c 2c 53 65  74 74 6c 65 6d 65 6e 74  |USD,,,Settlement|
00000240  20 6f 66 20 70 75 72 63  68 61 73 65 2e 2c 2c 31  | of purchase.,,1|
00000250  0a 0a 61 62 63 64 2c 37  38 39 37 35 36 2c 32 30  |..abcd,789756,20|
00000260  31 34 30 32 31 31 2c 32  30 31 34 30 32 30 32 2c  |140211,20140202,|
00000270  34 36 34 35 33 32 2e 30  30 2c 43 2c 58 5a 59 2c  |464532.00,C,XZY,|
00000280  2c 2c 53 65 74 74 6c 65  6d 65 6e 74 20 6f 66 20  |,,Settlement of |
00000290  70 75 72 63 68 61 73 65  2e 2c 2c 31 0a 61 62 63  |purchase.,,1.abc|
000002a0  64 2c 37 39 35 31 35 36  2c 32 30 31 34 30 32 31  |d,795156,2014021|
000002b0  31 2c 32 30 31 34 30 32  30 32 2c 35 34 38 39 36  |1,20140202,54896|
000002c0  32 2e 35 32 2c 43 2c 4a  50 59 2c 2c 2c 50 61 79  |2.52,C,JPY,,,Pay|
000002d0  65 6d 65 6e 74 20 74 6f  3a 20 74 6f 6b 79 6f 20  |ement to: tokyo |
000002e0  42 4e 46 3d 4e 2c 2c 31  0a 61 62 63 64 2c 37 36  |BNF=N,,1.abcd,76|
000002f0  33 32 35 36 2c 32 30 31  34 30 32 31 31 2c 32 30  |3256,20140211,20|
00000300  31 34 30 32 30 32 2c 34  32 31 38 38 2e 38 30 2c  |140202,42188.80,|
00000310  43 2c 55 53 44 2c 2c 2c  72 65 63 69 65 76 65 64  |C,USD,,,recieved|
00000320  20 66 72 6f 6d 20 2c 2c  31 0a 61 62 63 64 2c 37  | from ,,1.abcd,7|
00000330  35 36 35 35 36 2c 32 30  31 34 30 32 31 31 2c 32  |56556,20140211,2|
00000340  30 31 34 30 32 30 32 2c  34 35 36 38 39 38 2e 32  |0140202,456898.2|
00000350  38 2c 43 2c 45 55 52 2c  2c 2c 50 61 79 6d 65 6e  |8,C,EUR,,,Paymen|
00000360  74 20 76 69 61 2e 2c 2c  31 0a 61 62 63 64 2c 37  |t via.,,1.abcd,7|
00000370  33 32 36 35 36 2c 32 30  31 34 30 32 31 31 2c 32  |32656,20140211,2|
00000380  30 31 34 30 32 30 32 2c  35 38 34 36 31 2e 31 30  |0140202,58461.10|
00000390  2c 43 2c 49 4e 52 2c 2c  2c 53 65 74 74 6c 65 6d  |,C,INR,,,Settlem|
000003a0  65 6e 74 20 6f 66 20 70  75 72 63 68 61 73 65 2e  |ent of purchase.|
000003b0  2c 2c 31 0a 61 62 63 64  2c 37 39 38 37 35 36 2c  |,,1.abcd,798756,|
000003c0  32 30 31 34 30 32 31 31  2c 32 30 31 34 30 32 30  |20140211,2014020|
000003d0  32 2c 33 32 33 31 35 36  2e 38 32 2c 43 2c 41 55  |2,323156.82,C,AU|
000003e0  44 2c 2c 2c 53 65 74 74  6c 65 6d 65 6e 74 20 6f  |D,,,Settlement o|
000003f0  66 20 70 75 72 63 68 61  73 65 2e 2c 2c 31 0a 61  |f purchase.,,1.a|
00000400  62 63 64 2c 37 38 39 38  35 36 2c 32 30 31 34 30  |bcd,789856,20140|
00000410  32 31 31 2c 32 30 31 34  30 32 30 32 2c 38 34 36  |211,20140202,846|
00000420  32 31 2e 36 33 2c 43 2c  43 48 46 2c 2c 2c 53 65  |21.63,C,CHF,,,Se|
00000430  74 74 6c 65 6d 65 6e 74  20 6f 66 20 73 61 6c 65  |ttlement of sale|
00000440  20 6e 6f 20 42 33 35 34  35 33 20 45 55 52 20 34  | no B35453 EUR 4|
00000450  37 31 2e 36 30 2c 2c 31  0a 61 62 63 64 2c 37 38  |71.60,,1.abcd,78|
00000460  35 34 35 36 2c 32 30 31  34 30 32 31 31 2c 32 30  |5456,20140211,20|
00000470  31 34 30 32 30 32 2c 38  36 34 32 31 2e 34 30 2c  |140202,86421.40,|
00000480  43 2c 55 53 44 2c 2c 2c  53 65 74 74 6c 65 6d 65  |C,USD,,,Settleme|
00000490  6e 74 20 6f 66 20 70 75  72 63 68 61 73 65 2e 2c  |nt of purchase.,|
000004a0  2c 31 0a 0a 61 62 63 64  2c 37 38 39 37 35 36 2c  |,1..abcd,789756,|
000004b0  32 30 31 34 30 32 31 31  2c 32 30 31 34 30 32 30  |20140211,2014020|
000004c0  32 2c 34 36 34 35 33 32  2e 30 30 2c 43 2c 58 5a  |2,464532.00,C,XZ|
000004d0  59 2c 2c 2c 53 65 74 74  6c 65 6d 65 6e 74 20 6f  |Y,,,Settlement o|
000004e0  66 20 70 75 72 63 68 61  73 65 2e 2c 2c 31 0a 61  |f purchase.,,1.a|
000004f0  62 63 64 2c 37 39 35 31  35 36 2c 32 30 31 34 30  |bcd,795156,20140|
00000500  32 31 31 2c 32 30 31 34  30 32 30 32 2c 35 34 38  |211,20140202,548|
00000510  39 36 32 2e 35 32 2c 43  2c 4a 50 59 2c 2c 2c 50  |962.52,C,JPY,,,P|
00000520  61 79 65 6d 65 6e 74 20  74 6f 3a 20 74 6f 6b 79  |ayement to: toky|
00000530  6f 20 42 4e 46 3d 4e 2c  2c 31 0a 61 62 63 64 2c  |o BNF=N,,1.abcd,|
00000540  37 36 33 32 35 36 2c 32  30 31 34 30 32 31 31 2c  |763256,20140211,|
00000550  32 30 31 34 30 32 30 32  2c 34 32 31 38 38 2e 38  |20140202,42188.8|
00000560  30 2c 43 2c 55 53 44 2c  2c 2c 72 65 63 69 65 76  |0,C,USD,,,reciev|
00000570  65 64 20 66 72 6f 6d 20  2c 2c 31 0a 61 62 63 64  |ed from ,,1.abcd|
00000580  2c 37 35 36 35 35 36 2c  32 30 31 34 30 32 31 31  |,756556,20140211|
00000590  2c 32 30 31 34 30 32 30  32 2c 34 35 36 38 39 38  |,20140202,456898|
000005a0  2e 32 38 2c 43 2c 45 55  52 2c 2c 2c 50 61 79 6d  |.28,C,EUR,,,Paym|
000005b0  65 6e 74 20 76 69 61 2e  2c 2c 31 0a 61 62 63 64  |ent via.,,1.abcd|
000005c0  2c 37 33 32 36 35 36 2c  32 30 31 34 30 32 31 31  |,732656,20140211|
000005d0  2c 32 30 31 34 30 32 30  32 2c 35 38 34 36 31 2e  |,20140202,58461.|
000005e0  31 30 2c 43 2c 49 4e 52  2c 2c 2c 53 65 74 74 6c  |10,C,INR,,,Settl|
000005f0  65 6d 65 6e 74 20 6f 66  20 70 75 72 63 68 61 73  |ement of purchas|
00000600  65 2e 2c 2c 31 0a 61 62  63 64 2c 37 39 38 37 35  |e.,,1.abcd,79875|
00000610  36 2c 32 30 31 34 30 32  31 31 2c 32 30 31 34 30  |6,20140211,20140|
00000620  32 30 32 2c 33 32 33 31  35 36 2e 38 32 2c 43 2c  |202,323156.82,C,|
00000630  41 55 44 2c 2c 2c 53 65  74 74 6c 65 6d 65 6e 74  |AUD,,,Settlement|
00000640  20 6f 66 20 70 75 72 63  68 61 73 65 2e 2c 2c 31  | of purchase.,,1|
00000650  0a 61 62 63 64 2c 37 38  39 38 35 36 2c 32 30 31  |.abcd,789856,201|
00000660  34 30 32 31 31 2c 32 30  31 34 30 32 30 32 2c 38  |40211,20140202,8|
00000670  34 36 32 31 2e 36 33 2c  43 2c 43 48 46 2c 2c 2c  |4621.63,C,CHF,,,|
00000680  53 65 74 74 6c 65 6d 65  6e 74 20 6f 66 20 73 61  |Settlement of sa|
00000690  6c 65 20 6e 6f 20 42 33  35 34 35 33 20 45 55 52  |le no B35453 EUR|
000006a0  20 34 37 31 2e 36 30 2c  2c 31 0a 61 62 63 64 2c  | 471.60,,1.abcd,|
000006b0  37 38 35 34 35 36 2c 32  30 31 34 30 32 31 31 2c  |785456,20140211,|
000006c0  32 30 31 34 30 32 30 32  2c 38 36 34 32 31 2e 34  |20140202,86421.4|
000006d0  30 2c 43 2c 55 53 44 2c  2c 2c 53 65 74 74 6c 65  |0,C,USD,,,Settle|
000006e0  6d 65 6e 74 20 6f 66 20  70 75 72 63 68 61 73 65  |ment of purchase|
000006f0  2e 2c 2c 31 0a 0a                                 |.,,1..|
000006f6
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
# 38  
Old 02-25-2014
@Scrutinizer i'm using windows 7 enterprise!

@Everyone- thanks all for your time. All the codes that you gave worked perfectly on a different system running on unix.

Below code worked both on windows and unix.

Code:
 
perl -pi.orig -e '$/=undef; s/,[\r\n]+/,/g;s/[\r\n]+,/,/g' sample.csv


Just a curious doubt.

Till now we were correcting the file when a record was split where there a comma like this:
Code:
 
abcd,789756,20140211,20140202,
464532.00,C,XZY,,,Settlement of purchase.,,1

or

Code:
 
abcd,789756,20140211,20140202
,464532.00,C,XZY,,,Settlement of purchase.,,1

And now what if a record is broken in the data itself like this

Code:
 
abcd,789756,20140211,2014
0202,464532.00,C,XZY,,,Settlement of purchase.,,1

# 39  
Old 02-26-2014
Any help?
# 40  
Old 02-26-2014
My awk code would work, but not on a Windows system as you noticed.. But since this is a Unix forum and not a Windows forum and I do not have a Windows box handy, I would not know what you have to do to get it working there. Perhaps others know?
# 41  
Old 02-26-2014
If you do not mind a long-long code.
Try this, modified from your code too, I am sorry I am not very good at perl.
Code:
perl -pi.orig -e '$/=undef; s/([\r\n]+)([^\r\n,]*|[^\r\n,]*,[^\r\n,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*)[\r\n]+([^\r\n,]*|[^\r\n,]*,[^\r\n,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*|[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*,[^\r\n^,]*)([\r\n]+)/\1\2\3\4/g'

And hope anyone could guide me how to make the perl code easier, or make it in to wrap lines.

Last edited by Lucas_0418; 02-26-2014 at 07:49 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to auto correct a failing command?

If a command is not found, e.g. nawk, this is how I fix the problem ] && NAWK=/usr/bin/gawk ] && NAWK=/usr/bin/nawk ] && NAWK=/usr/bin/awkI use $NAWK an the set the appropriate value based on the system it runs. How can I implement a similar fix for a command found but illegal argument.... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Beginners Questions & Answers

How to zip csv files having specific pattern in a directory using UNIX shell script?

I have files in a Linux directory . Some of the file is listed below -rw-rw-r--. 1 roots roots 0 Dec 23 02:17 zzz_123_00000_A_1.csv -rw-rw-r--. 1 roots roots 0 Dec 23 02:18 zzz_121_00000_A_2.csv -rw-rw-r--. 1 roots roots 0 Dec 23 02:18 zzz_124_00000_A_3.csv drwxrwxr-x. 2 roots roots 6 Dec 23... (4 Replies)
Discussion started by: Balraj
4 Replies

3. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

4. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

5. Post Here to Contact Site Administrators and Moderators

Auto correct a csv file using UNIX shell script.

Hi All, There are list of 4-5 .csv files which has 12 columns.In some cases one of the record is split into 2 records. What needs to be done is this split record has to be auto corrected and placed in the csv file. Eg: Let us consider sample.csv file and in normal conditions the file... (1 Reply)
Discussion started by: karthik_ak
1 Replies

6. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

7. Shell Programming and Scripting

Exporting data as a CSV file from Unix shell script

Friends...This is the first time i am trying the report generation using shell script... any suggestions are welcome. Is there a way to set the font size & color when i am exporting the data from unix shell script as a CSV file ? The following sample data is saved as a .csv file in the... (2 Replies)
Discussion started by: appu2176
2 Replies

8. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

9. UNIX for Advanced & Expert Users

Unix Shell Script with output to CSV File

Hi, I have a unix shell script that is outputting results from an SQL query to a *.csv file, using utl_file.put_line. The resulting file is then sent out via e-mail as a mail attachment. The issue I have is that when the mailed attachment is opened in Excel the first column is shown as... (1 Reply)
Discussion started by: heather.morton@
1 Replies

10. Shell Programming and Scripting

Modifying a csv file from Shell Script

Hi all, I have some script that creates a temp csv file. What I need to do is do some search and replace and modify the file from my shell script. I know the commands to open the file and then apply the reg ex but wasnt sure how I could do this from a script and modify the file? Any help... (2 Replies)
Discussion started by: not4google
2 Replies
Login or Register to Ask a Question