remove whitespace and test


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove whitespace and test
# 1  
Old 09-25-2003
remove whitespace and test

Hi,

I know removing whitespaces I can found so many threads to read how it works and i did it, but my problem isn't solved...

I have in my script a variable $1 which can contains a text like " Channel ".

No I want to check if $1 contains the word Channel, but I don't know how many whitespaces there are before and after the word...

I tried this:

if [ "Channel" = $1|awk '{print $1}'>$1 ] ; then
echo "found!!!"
fi

So where is the problem??
Sorry for this stupid question

Ben Sky
# 2  
Old 09-25-2003
Hi,

Might be a bit nasty, but what if you first strip of the whitespaces?

I know there are better ways to do this, but at least is a solution.

a=`echo $1 | sed s/\s+//`

Regs David
# 3  
Old 09-25-2003
David,
try:
a=`echo $1`


Bensky,
your if statement is a mess.

First, in a statement like
if [ ... ] ; then
you cannot put pipelines inside the braces unless the pipeline is inside backticks or something.

And a pipeline must connect commands line this " ps -ef | more". $1 is not a command.

If $1 was " command " as you said, > $1 would send the output of the awk command into a file called command.

I've been staring at your if statement for 10 minutes and I still can't figure out what you're trying to do. I assume that you want to both perform a test and have a cool side effect all in one fell swope. But I don't know what side effect you're looking for.

You should consider switching to ksh so that you can use
if [[ .... ]] ; then
# 4  
Old 09-25-2003
Hi


David I tested your statement, and it works, if i do this in the prompt, but if I include this in my script it doesn't work:

a=`echo $1 | sed s/\s+//`
echo "!${a}!"

there are still whitespaces...

also with the version from Perderabo I have this problem...

What I'am trying to do is, to test if the content of the variable $1 is "Channel" or not...
I hope soon my coding gets better, so that it is more clear what I like to do..

Ben Sky
# 5  
Old 09-25-2003
Computer

Hi,

I found the error..

I had set the
IFS="|" so that than the echo also printed out the whitespaces...

Thanks for your help

Ben Sky
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] How remove leading whitespace from xml (sed /awk?)

Hi again I have an xml file and want to remove the leading white space as it causes me issues later in my script I see sed is possible but cant seem to get it to work I tried sed 's/^ *//' file.xml output <xn:VsDataContainer id="1U104799" modifier="update"> ... (10 Replies)
Discussion started by: aniquebmx
10 Replies

2. Shell Programming and Scripting

Remove whitespace after pipe symbol but not inside words

I have a file that looks like this: 102| #2 X 1/4-INCH| 30188| EA| FTW| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #2 X 1/4-INCH| 30188| EA| VPS| A| NOT SERIAL TRACKING| NOT LOT TRACKING| TRUE| #2 X 1/4-INCH 102| #6 X 1/2"| ... (2 Replies)
Discussion started by: djehresmann
2 Replies

3. Shell Programming and Scripting

Sed: Remove whitespace between two strings

I have a 13 number string, some whitespace, and then /mp3. I need to join them. Everyline that I need this for begins with "cd" (without the quotes). What it looks like now: cd media/Audio/WAVE/9781933976334 /mp3 What I want my output to be: cd media/Audio/WAVE/9781933976334/mp3 The 13... (7 Replies)
Discussion started by: glev2005
7 Replies

4. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

7. UNIX for Dummies Questions & Answers

remove whitespace

I combined 2 files using the paste command. It gave me something like this: 123445 ,AABBNN 22344 ,BBVVMM I want to remove the whitespace between the end of string 1 and the comma (there is more blank space than my post is showing). Would I... (2 Replies)
Discussion started by: nickg
2 Replies

8. UNIX for Dummies Questions & Answers

rm: Unable to remove directory /mnt/users/test/logs/: File exists

rm: Unable to remove directory /mnt/users/test/logs/: File exists ls -latr total 191208 drwxrwxrwx 6 test echo 4096 Jul 3 22:36 .. -rwxrwxrwx 1 test echo 97692804 Jul 3 22:36 .nfsDFA4 drwxrwxr-x 2 test echo 4096 Jul 3 23:00 . M not able to delete... (4 Replies)
Discussion started by: solitare123
4 Replies

9. Shell Programming and Scripting

sed : remove whitespace

I'm trying to remove the whitespace at the end of each line of a text file in ksh. Im using sed s/ $//g' file1.txt > file2.txt It's not working. Any clues? (3 Replies)
Discussion started by: b.hamilton
3 Replies
Login or Register to Ask a Question