Convert Batch Script to Bash

Hello Experts,

I would like to get this batch code converted to bash,

for /f "tokens=1,2" %i in ('ucommand -list ^| find /i "_ud"') do @command -f %j -user %i -delete

TunerMLSystems EngineerAsked:
Who is Participating?
MikeOM_DBAConnect With a Mentor Commented:
Works for me:
==> ucommand -list | grep -i "_ud" | while read u f x;do echo "./command -f $f -user $u -delete"; done
./command -f ???_???_UD -user user1 -delete
./command -f ???_???_UD -user user2 -delete
./command -f ???_???_UD -user user3 -delete
./command -f ???_???_UD -user user4 -delete
./command -f ???_???_UD -user user5 -delete
./command -f ???_???_UD -user user6 -delete
./command -f ???_???_UD -user user7 -delete
./command -f ???_???_UD -user device1 -delete
./command -f ???_???_UD -user device2 -delete

Open in new window

PS: Remove the echo and quotes to execute the commands...
Assuming you already converted the "ucommand" and "command" programs, try this:

for line in `ucommand -list | grep -i "_ud"`
  i=`echo $line | cut -d" " -f1`
  j=`echo $line | cut -d" " -f2`
  command -f $j -user $i -delete

Open in new window

TunerMLSystems EngineerAuthor Commented:
Any possible way for it to be a one-liner? or would I need to put this in a. sh file and set chmod +x?
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

TintinConnect With a Mentor Commented:
ucommand -list | grep -i "_ud" | xargs -n2 -sh -c 'command -f $2 -user $1 -delete' argv0

Open in new window


ucommand -list | grep -i "_ud" | while read i j ; do command -f $j -user $i -delete; done

Open in new window

TunerMLSystems EngineerAuthor Commented:
Tried all of the above scripts and encountered errors even with some tweaking though my scripting knowledge in Unix is severely limited.

Okay so a sample output of the ./command -list would be:

"Update information...

user1 ???_???_UD year.mmdd
user2 ???_???_UD year.mmdd
user3 ???_???_UD year.mmdd
user4 ???_???_UD year.mmdd
user5 ???_???_UD year.mmdd
user6 ???_???_UD year.mmdd
user7 ???_???_UD year.mmdd

device1 ???_???_UD year.mmdd
device2 ???_???_UD year.mmdd


What I'm trying to achieve is a script that allows me to run this command for each user;

./command -f ???_???_UD -user user1 -delete
./command -f ???_???_UD -user user2 -delete
./command -f ???_???_UD -user user3 -delete

and so fourth.
TunerMLSystems EngineerAuthor Commented:
Wouldn't have thought to remove the echo or quotes, Thanks guys.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.