I have a shell script that is outputting from a database. What is coming from the DB is this:

-----------
50

(1 rows affected)

The issue that I have is there is an if statement in my script that looks at the first line and reads the number there. Unfortunately because of how this comes out it reads either the blank line or the hyphen as an invalid character and throws an error. I know you can use SED to remove unwanted text and spaces however I'm not sure exactly how to put it together in this instance. I do have an SED command in my script:

${SED} 's/  */ /g' <extract_dt.txt > temp.txt

From what I have been told this just replaces any time there is two spaces in a row with one space but I need it to do a bit more than that for my purposes. Ideally I'd want to trim everything that's not the number but if I can at least get the number on the top row that would be just fine. Thanks.

I think you could use sed or egrep.

$ cat test.txt 
-----------
50 

(1 rows affected)
$ sed -ne '/^[0-9]/p' test.txt 
50 
$ egrep "^[0-9]" test.txt 
50 
$
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.