string manipulation in bash shell

Hi All,

I am using a bash shell and want to the following thing.

A process sends the following string to my script

BACKUP_FAIL_REASON="Failed - Application Dump CDMACA-0:grep: /opt/nortel/ca/data/1245184/sd00/image1/S110907070708HIS
/opt/nortel/ca/data/1376256/sd00/image1/S110906070712HIS
/opt/nortel/ca/data/1376256/sd00/images/S110906010711HIS
/opt/nortel/ca/data/1376256/sd00/image1/S110906070712HIS
/opt/nortel/ca/data/1376256/sd01/image1/S110907010713HIS
/opt/nortel/ca/data/1376256/sd01/images/S110907070713HIS"

As you can see the string that i have has multiple newlines in it.

Please suggest me a mechanism to manipulate the string so as to remove the newlines from the string.

After the manipulation my string should contain no newlines and should have all the strings separated by spaces only.

Thanks,
Sachin

Google Search Results for remove newline | The UNIX and Linux Forums

1 Like
$ echo "$BACKUP_FAIL_REASON" | xargs
1 Like

Thanks for ur replys buddy :):slight_smile:

I adopted the following to produce the desired result

BACKUP_FAIL_REASON = `echo -e "${BACKUP_FAIL_REASON}" | tr "\n" " "

If you remove the quotes from around "${BACKUP_FAIL_REASON}" you won't need the tr, echo will flatten it by itself.