划分脚本以删除rown,其中列值在“ in”中。和“ br&quot”

发布于 2025-02-13 23:16:35 字数 398 浏览 1 评论 0原文

我有一个CSV文件,该文件具有35列,在第19列中,我得到了这些国家价值,例如IN,BR,US等。我需要删除第19列中国家价值的行和Br。

我尝试了以下问题,但有很多问题,因为我只能使用令牌直至26,也无法在BR中使用。

@echo off &setlocal
set /p "header="<"old.csv"
>"your new.csv" echo.%header%
for /f "usebackq skip=1 delims=, tokens=1-26*" %%a in ("old.csv") do (
  if not "%%t" == "BR" 
  (
    >>"your new.csv" echo.%%a,%%b,%%c,%%d.....,%%Z
  )
)

I Have a csv file which has 35 columns and in 19th column i get these country values like IN, BR, US etc. I need to remove the rows where the country value in 19th column is IN and BR.

I tried the following but has many issues as i can use tokens upto 26 only and also not being able to use both IN and BR.

@echo off &setlocal
set /p "header="<"old.csv"
>"your new.csv" echo.%header%
for /f "usebackq skip=1 delims=, tokens=1-26*" %%a in ("old.csv") do (
  if not "%%t" == "BR" 
  (
    >>"your new.csv" echo.%%a,%%b,%%c,%%d.....,%%Z
  )
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雅心素梦 2025-02-20 23:16:35

这应该有效:

@echo off
setlocal EnableDelayedExpansion

set "remove=IN|BR"

set /P "header=" < "old.csv"

> "your new.csv" (
   echo %header%
   for /F "usebackq skip=1 delims=, tokens=1-19*" %%a in ("old.csv") do (
      if "!remove:%%~s=!" equ "%remove%" (
         echo %%a,%%b,%%c,%%d,...,%%s,%%t
      )
   )
)

for /?< /code>帮助屏幕:

如果令牌=字符串中的最后一个字符是星号,则
分配了附加变量,该变量接收其余文本
最后分析令牌后的线。

换句话说,在以前的代码中,%% T令牌接收所有列在第19个...之后...

This should work:

@echo off
setlocal EnableDelayedExpansion

set "remove=IN|BR"

set /P "header=" < "old.csv"

> "your new.csv" (
   echo %header%
   for /F "usebackq skip=1 delims=, tokens=1-19*" %%a in ("old.csv") do (
      if "!remove:%%~s=!" equ "%remove%" (
         echo %%a,%%b,%%c,%%d,...,%%s,%%t
      )
   )
)

From the FOR /? help screen:

If the last character in the tokens= string is an asterisk, an
additional variable is assigned that receive the rest of the text in
the line after the last analyzed token.

In other words, in previous code the %%t token receive all the columns after the 19th one...

虐人心 2025-02-20 23:16:35
@echo off

setlocal

set "remove1=IN"
set "remove2=BR"

set /P "header=" < "old.csv"

> "your new.csv" (
   echo %header%
   for /F "usebackq skip=1 delims=" %%e in ("old.csv") do (
    for /F "delims=, tokens=19" %%b in ("%%e") do (
      if "%remove1%" neq "%%~b" if "%remove2%" neq "%%~b" (
         echo %%e
      )
    )
   )
)

[未经测试]

...但请记住评论中的要点。

@echo off

setlocal

set "remove1=IN"
set "remove2=BR"

set /P "header=" < "old.csv"

> "your new.csv" (
   echo %header%
   for /F "usebackq skip=1 delims=" %%e in ("old.csv") do (
    for /F "delims=, tokens=19" %%b in ("%%e") do (
      if "%remove1%" neq "%%~b" if "%remove2%" neq "%%~b" (
         echo %%e
      )
    )
   )
)

[untested]

...but keep in mind the points raisd in the comments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文