Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pipe output into a delete command

i am trying to delete files created by this command cleartool ls -r -view_only

The output looks like .\noc\shared\dpcversioninfo.rc.keep

I want to pipe this into a del command like cleartool ls -r -view_only|del /q and get bad syntax.

like image 615
user4067896 Avatar asked Mar 23 '26 05:03

user4067896


1 Answers

del command does not read data from stdin. You will need to retrieve the output of the cleartool command and use it as argument to del

The way to do it in windows is to use a for /f command. It can execute a command and iterate over its output lines, executing the code after the do clause for each of them, with the contents of the line stored in the indicated replaceable parameter (the for variable)

@echo off
    setlocal enableextensions disabledelayedexpansion

    for /f "delims=" %%a in ('cleartool ls -r -view_only') do echo del /q "%%a"

This will echo to console the del commands. If the output is correct, remove the echo command.

like image 91
MC ND Avatar answered Mar 24 '26 23:03

MC ND



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!