问题
With a bit of time on my hands, I have a WINDOWS batch script to fuzzy find inside my exported Google Contacts. The selected export format is Google CSV - and no surprise it isn't easy work!
After fixing the current directory my script processes a seed parameter for fzf.exe --query option.
We then pipe the raw export:
- Using cut and tr to select some useful fields.
- Next is the fzf interface - brilliant!
- Then we make a list by adding newlines
- Finally we copy the output, then display a numbered list
Using set we get an input, check for a number above zero and then place that line on the clipboard.
@echo off
REM Change to current cmd directory where all the tools are
cd /D "%~dp0"
REM Find people in my text file - exported from Google contacts
REM Check %1 in not null
If [%1]==[] (
set SEED=""
) ELSE (
set SEED=%1
)
REM Run the fzf over a sanitized selection from contactsGoogle.csv (and store final result)
cut -d, -f 1,31,33,35,37,39,41,43,45,47,49 ..\ZLISTS\contactsGoogle.csv | tr -s "," ":" | tr -s " :" ":" | fzf.exe --reverse --query=%SEED% | tr ":" "\n" | tee xp.txt | cat -n
REM Ask for input
echo.
set /P "line=Select line to copy : "
REM Process resulting line number
if %line%=="0" goto End
REM Check for number
SET "var="&for /f "delims=0123456789" %%i in ("%line%") do set var=%%i
if defined var ( goto End ) else (
sed -n %line%p xp.txt | tr -d '\n'| clip
)
:End
Q1. How can I replace all the newlines inside double quotes, in the raw google csv format exported file, with spaces. Please note it is only the troublesome fields with newlines that have any quotes. Also this is WINDOWS so escaping and quoting commands to SED/AWK/GREP is a nightmare .
Q2. Once I get past this problem - will cut.exe see commas inside double quotes?
Many thanks in advance
Kind Regards Gavin Holt
来源:https://stackoverflow.com/questions/60870977/fuzzy-find-using-exported-google-contacts-remove-newline-inside-double-quotes