string manipulation in bash shell


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users string manipulation in bash shell
# 1  
Old 09-08-2011
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
# 2  
Old 09-08-2011
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 09-08-2011
Code:
$ echo "$BACKUP_FAIL_REASON" | xargs

This User Gave Thanks to jayan_jay For This Post:
# 4  
Old 09-12-2011
Thanks for ur replys buddy SmilieSmilie

I adopted the following to produce the desired result

BACKUP_FAIL_REASON = `echo -e "${BACKUP_FAIL_REASON}" | tr "\n" " "
# 5  
Old 09-12-2011
If you remove the quotes from around "${BACKUP_FAIL_REASON}" you won't need the tr, echo will flatten it by itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a string to variable in Bash shell

Hi All; I have 2 variable let's say $A and $B. These are actually some remotely executed command outputs. I captured these values in my local variables. Here is my problem. When I try to do some arithmetic operation with these variables, I receive an error message. Neither expr nor typeset -i... (3 Replies)
Discussion started by: Meacham12
3 Replies

2. Shell Programming and Scripting

Bash string manipulation

In my script I'm retrieving a parameter through an API call. I need to trim some things out of the result so I can use it as a parameter to pass to another process. I've got it working but it's pretty kludgy and I'm hoping someone can help me with a better way. This is the code that retrieves... (2 Replies)
Discussion started by: withanh
2 Replies

3. Shell Programming and Scripting

bash string manipulation

Hello guys, here is my problem: I got a shell script which is called by an external piece of software, the external software is not under my control. The software passes data as an argument to my script like ./bla.sh 'service;1234567890;ok;hostname;some text here' I need to pass the... (3 Replies)
Discussion started by: snoogie
3 Replies

4. Shell Programming and Scripting

How can we create a string table in bash shell ?

Hello, How can we write the pseudo code below using Bash shell scripting? table = ; i=0; do{ grep table h.txt; }while(i<3); or table = ; i=0; for(i=0;i<3;i++) grep table h.txt; (4 Replies)
Discussion started by: dbgork
4 Replies

5. Shell Programming and Scripting

sed string manipulation in shell script

Hello, I have 1000 of sql queries and i need to push column value in query. e.g. SET INSERT_ID=1 INSERT INTO test (id,name) VALUES ('a'); SET INSERT_ID=2 INSERT INTO test (id,name) VALUES ('b'); SET INSERT_ID=3 INSERT INTO test (id,name) VALUES ('c'); SET INSERT_ID=4 INSERT INTO test... (12 Replies)
Discussion started by: mirfan
12 Replies

6. Shell Programming and Scripting

SPLIT STRING in bash shell script

i need one help.... if i have a string like aaaaa,bbbbb,ccccc,aaaaa How to to split the string and check howmany times aaaaa will be in that string? Thanks (7 Replies)
Discussion started by: karthinvk
7 Replies

7. Shell Programming and Scripting

Shell scripting string manipulation

Hi, if I have a string delimited by commas how can I put each character on a new line followed by a carriage return, and output this to a filee.g from: s,t,r,i,n,g to s t r i n g thanks you (3 Replies)
Discussion started by: Wahmed9
3 Replies

8. Shell Programming and Scripting

Bash string variable manipulation

In a bash script I've set a variable that is the directory name of where an executable lives. the_dir=`dirname $which myscript` which equates to something like "/path/to/dir/bin" I need to cut that down to remove the "bin" so I now have "/path/to/dir/". This sounds easy but as a... (2 Replies)
Discussion started by: Witty
2 Replies

9. Shell Programming and Scripting

bash shell script string comparison

I want to remove a line that has empty string at second field when I use cut with delimeter , like below $cat demo hello, mum hello, #!/bin/sh while read line do if then # remove the current line command goes here fi done < "demo" i got an error message for above... (4 Replies)
Discussion started by: bonosungho
4 Replies

10. Shell Programming and Scripting

split files by specifying a string (bash shell)

Hi all, I have a file of around 300 lines in which string "SERVER" occurs around 32 times. for eg. I need to split files like, for eg I am using this code awk '/SERVER/{n++}{print > f n}' f=/vikas/list /vikas/final But the problem is that it makes maximum of 10 files, but I... (12 Replies)
Discussion started by: vikas027
12 Replies
Login or Register to Ask a Question