Fuzzy find using exported google contacts: remove newline inside double quotes

断了今生、忘了曾经 提交于 2020-04-17 20:37:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!