0

I'm trying to use a bash script to sanitize a database and I need to use the largest ID Number from the users table so I have this line in my script

MAXID=$(mysql -u root -proot elis27 -e "select max(idnumber) from mdl_user;")
echo $MAXID

And the output of that line in my script is

max(idnumber) 3

How can I parse the output of the mysql command so that MAXID is just 3?

0

2 Answers 2

1

Use the --skip-column-names (or -N for short) option to omit column name headings in the output:

MAXID=$(mysql -u root -proot -N elis27 -e "select max(idnumber) from mdl_user;")
Sign up to request clarification or add additional context in comments.

1 Comment

Gah. Beat me by 18 seconds (+1).
1

I'll let you put the awk statement in maxid declaration, here is simple logic to get 3 -

a="max(idnumber) 3"
b=`echo $a | awk '{print $2}'`;echo $b

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.