0

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.

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by histrungalot
0

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 
$
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.