whitespace problem


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users whitespace problem
# 1  
Old 02-19-2009
whitespace problem

I have a single string as below:

Rat run after Cat[whitespace]

i.e. there is a single whitespace after Cat.

This causes my file to fail.

Is there a way I can remove any whitespace at the end of any string.

I tried sed 's/ *//g', but it removes all white space and the above string becomes like this RatrunafterCat. But i dont want the format to be changed. Plz help.
Thanks,
# 2  
Old 02-19-2009
sed "s/ \s*$//"

" \s*" - replace one or more spaces
"$ " - at the end
# 3  
Old 02-19-2009
Zedex,
First of all thanks,

is this command ok with one quotation mark and I put a g[global] .I also removed a space before \s from what u gave

sed 's/\s*$//g' x.csv>y.csv

It however didnt do the purpose. Am i wrong somewhere.

Thanks,
# 4  
Old 02-19-2009
I think I interpreted my problem wrongly.

this white space is in a column middle of the file>
columna columnb columnc columnd
tom rom[whitespace] pom som
tok ghom poch[whitespace] zom

so i need to remove the whitespace from column b and columnc only and that too everytime at the end of the string.

Is there any way. Sorry abt that.

Thanks,
# 5  
Old 02-20-2009
Quote:
Originally Posted by RubinPat
I think I interpreted my problem wrongly.

this white space is in a column middle of the file>
columna columnb columnc columnd
tom rom[whitespace] pom som
tok ghom poch[whitespace] zom

so i need to remove the whitespace from column b and columnc only and that too everytime at the end of the string.

Is there any way. Sorry abt that.

Thanks,
rubinpat

if columns are not separated by space then what is the separator ? if possible provide some actual data ..
# 6  
Old 02-20-2009
Again sorry zedex, the fields are comma delimited


columna, columnb, columnc, columnd,
tom dom, rom pom[whitespace], pom pok, som pok
tok dok, ghom gok, poch gok[whitespace], zom zok


There is a single space or whitespace before the comma delimiters which is createing problems. I tried to see what it is through cat -v but was unable to get what it is. I removed it through vi editor but that's not the permanent solution. When I use sed command to remove whitespace it removes all the whitespaces there in thus making my file look like below but that space is not gone

so i need to remove the whitespace or the hidden space from column b and columnc only and that too everytime at the end of the string.


Honestly I hv no clue whats that

Is there any way.

Thanks,
# 7  
Old 02-20-2009
Hammer & Screwdriver Can you do this?

Code:
> echo "tom dom, rom pom , pom pok, som pok"
tom dom, rom pom , pom pok, som pok
> echo "tom dom, rom pom , pom pok, som pok" | sed "s/ ,/,/"
tom dom, rom pom, pom pok, som pok

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate by more than whitespace.

This is my file .........hostname.............this is hostname .........alias...................alias name Remark use dot(.) instead of whitespace B'cuz this forum not allow to use more whitespace. --------------------------------------- I sperate by whitespace not work. awk 'BEGIN {FS=" "}... (4 Replies)
Discussion started by: cyberking
4 Replies

2. Shell Programming and Scripting

Getting rid of whitespace

Hello I am working aon script, that tells me how many users or on the system when i run it. The script is #!/bin/bash w | cut -f 1 -d ' ' |sort -u | wc -l When ran it shows 16 users including myself and a line of white space. I was wondering what I need to add to remove my user... (2 Replies)
Discussion started by: mosdojaf
2 Replies

3. 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

4. Shell Programming and Scripting

Cut and WhiteSpace Problem

Hi, I have a shell script that reads a parameter file to set variables. I have an issue when the parameter I try to read contains whitespace. e.g File Contents Code The result is SUBJECT is set to and I want subject set to I've tried different variations but nothing seems to... (19 Replies)
Discussion started by: Greygor
19 Replies

5. Shell Programming and Scripting

find grep whitespace problem

Hey guys iv written a basic function to ask for input location to find then grep a certain string in the file at the location of the find. For some reason it finds the file with the certain string it however it says directory not found on each string before the whitespace eg enter location to... (5 Replies)
Discussion started by: musicmancanora4
5 Replies

6. 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

7. Shell Programming and Scripting

Copy files listed in a text file - whitespace problem.

Hi, Say I have this text file <copy.out> that contains a list of files/directories to be copied out to a different location. $ more copy.out dir1/file1 dir1/file2 dir1/file3 "dir1/white space" dir1/file4 If I do the following: $copy=`more copy.out` $echo $copy dir1/file1... (4 Replies)
Discussion started by: 60doses
4 Replies

8. Shell Programming and Scripting

Whitespace Issues

Hello forums! I've been tinkering with a shell script to partition and restore content to a drive based on a type of file in a given directory. My goal is for my script to assemble several restore images, partition the drive based on the images and to then restore those images to the partitions... (1 Reply)
Discussion started by: rkasowan
1 Replies

9. Shell Programming and Scripting

Delete whitespace

Hi, I have been trying to remove whitespace from a file using sed. Here is an example of what im trying to do: www1 = www1 www2 = www2 www3 = www3 and all the way to 300 and i want it to look like: www1=www1 www2-www2 www3=www3 again upto 300 Any help... (12 Replies)
Discussion started by: truck7758
12 Replies

10. Shell Programming and Scripting

trim whitespace?

I'm trying to find a command that will trim the white space off a string. e.g. $str = " stuf " $str = trim ( $str ) echo $str // ouput would just be stuf Thanks, Mark (4 Replies)
Discussion started by: msteudel
4 Replies
Login or Register to Ask a Question