Showing posts with label Editors. Show all posts
Showing posts with label Editors. Show all posts

2014-08-12

Regular expressions for CSV files

SQL Server Import had troubles to import csv file, when some fields contained CRLF(\r\n).
Row delimiter needs to be changed.
Notepad++ was used.

It matches 15 columns (14 comma delimiters). CRLF is end of line. Some text columns contain CRLF(\r\n).
((?:(?:"(?:(?:""|[^"])+)"|(?:[^,]*)),){14}.*?)\r\n
to add a pipe as row delimiter replace with \1|\r\n

it matches $$ delimiter 7 fields (6 delimiters) and end of line \r MAKE sure . dot matches end of LINE!
(?:.*?\$\$){6}.*?\r
((?:.*?\$\$){13}.*?)\r\n   to add a pipe as row delimiter replace with \1|\r\n 

to search for $$ with grep (Linux or Cygwin), use single quotes and escape last dollar
grep -e '$\$' filename.csv

2011-11-28

Editors handy commands

Insert TEXT at beginning of a line
Notepad++
Search mode – regular expression
Find:   
^(.)
Replace with:   
TEXT\1

Vi
:%s/^/TEXT/

Append TEXT to end of a line
Notepad++
Search mode – regular expression
Find:
(.)$
Replace with:   
\1TEXT

Vi
:%s/$/TEXT/

Delete blank lines
Notepad++
Menu: TextFX -> TextFX Edit -> Delete blank lines

vi
:g/^$/d
Blank line with spaces (there is a space after backslash):
:g/^\ *$/d

Find “db.world” and replace with “db, db.world”
Notepad++
Search mode – regular expression
Find:   
^(\w*).world
Replace with:   
\1, \1.world