Sponsored Content
Top Forums Shell Programming and Scripting for loop ( string having spaces ) Post 302424626 by arvindng on Wednesday 26th of May 2010 01:17:35 AM
Old 05-26-2010
Dear Devaraj,

given code is not able to grep proper string( it is spliting )

following error occurred

Code:
sh -x yyy.sh 
+ 0< command.txt
+ read line
+ + echo aaaaa -t -v ttm -D -r RJLL -h YELP
+ cut -c 21-
i=r RJLL -h YELP
+ + grep r RJLL -h YELP command.txt
grep: can't open RJLL
grep: can't open -h
grep: can't open YELP
cmd=command.txt:aaaaa -t -v ttm -D -r RJLL -h YELP
command.txt:aaaaa -t -v ttm -D -r RJLL -h ERRT
command.txt:aaaaa -t -v ttm -D -r RJLL -h TYYE
command.txt:aaaaa -t -v ttm -D -r RJLL -h POOL
+ echo command.txt:aaaaa -t -v ttm -D -r RJLL -h YELP command.txt:aaaaa -t -v ttm -D -r RJLL -h ERRT command.txt:aaaaa -t -v ttm -D -r RJLL -h TYYE command.txt:aaaaa -t -v ttm -D -r RJLL -h POOL
command.txt:aaaaa -t -v ttm -D -r RJLL -h YELP command.txt:aaaaa -t -v ttm -D -r RJLL -h ERRT command.txt:aaaaa -t -v ttm -D -r RJLL -h TYYE command.txt:aaaaa -t -v ttm -D -r RJLL -h POOL
+ + ps -ef
+ wc -l
+ grep r RJLL -h YELP
+ grep -v grep
ps_cnt=0
+ [ 0 -gt 0 ]
+ command.txt:aaaaa -t -v ttm -D -r RJLL -h YELP command.txt:aaaaa -t -v ttm -D -r RJLL -h ERRT command.txt:aaaaa -t -v ttm -D -r RJLL -h TYYE command.txt:aaaaa -

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

For loop using find with file name spaces

Hello All, This question is actually for the service console of VMware ESX 3.5 but is relevant to this forum I think. I have been advised to use the following commands: for i in `find /vmfs/volumes/Test_VMFS/ -name "*.vmx"` do echo "$i" #sed -i 's/scsi1:0.present =... (3 Replies)
Discussion started by: mronsman
3 Replies

2. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

3. Shell Programming and Scripting

sed: replace string with another string (with spaces)

Hi I have an XML file with strings XABCD, XEFGHX and XIJKLX. I would like to replace XABCDX with "This is the first string", XEFGHX with "This is the second string" and XIJKLX with "This is the third string". What is the best way to implement this? Should I have a file with the data that is... (4 Replies)
Discussion started by: zmfcat1
4 Replies

4. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

5. Shell Programming and Scripting

problem with for loop and a variable with spaces...Hi

Hi there, I don't understand the following behavior: toto:~$ for word in un "deux trois"; do echo $word; done un deux trois toto:~$ sentence='un "deux trois"' toto:~$ for word in $sentence; do echo $word; done un "deux trois" toto:~$ sentence="un 'deux trois'" toto:~$ for word in... (10 Replies)
Discussion started by: chebarbudo
10 Replies

6. Shell Programming and Scripting

Having a for loop read in lines with spaces?

Is this possible? I have a for loop in a shell script reading a list, but I want each line to be a loop, not each thing with a space. Here is the example: HOSTLIST="\ 1.2.3.4 serverA 1.2.3.5 serverB" for NBUHOST in `echo $HOSTLIST` do ssh ${SERVERNAME} "echo "${NBUHOST}"... (3 Replies)
Discussion started by: LordJezoX
3 Replies

7. Shell Programming and Scripting

Loop with Find—damn spaces!

Hi Guys, I'm trying to find all files with a particular extension and then loop some actions. The problem is that if the files have spaces in their names I get end up being each word as a separate result rather than the entire file. ext=".txt" out=".rtf" for i in $( find "$1" -name "*$ext" );... (9 Replies)
Discussion started by: imonkey
9 Replies

8. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

9. Shell Programming and Scripting

Loop through array of arrays of string with spaces

Hi I'm trying to loop through an array that contains other arrays and these arrays consist of strings with spaces. The problem is that I can't seem to preserve the spacing in the string. The string with spaces are either divided into multiple items if I change IFS to \n or all the elements of... (4 Replies)
Discussion started by: kidmanos
4 Replies

10. Shell Programming and Scripting

Process files in loop which have spaces in name

I have a folder with files and I have to process them in a loop. However the filenames have space characters, so the list get split. $ touch "File Number_1" $ touch "File Number_2" $ ls "/tmp/File Number"_* /tmp/File Number_1 /tmp/File Number_2 I tried following (sorry for using the... (3 Replies)
Discussion started by: Wernfried
3 Replies
All times are GMT -4. The time now is 08:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy