Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Using sed to delete everything after "space"

Shell Programming and Scripting


Tags
grep, sed, solved, space

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Stefan Willms
Stefan Willms's Unix or Linux Image
Stefan Willms Stefan Willms is offline
Registered User
 
Join Date: Jan 2018
Last Activity: 12 January 2018, 7:16 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Using sed to delete everything after "space"

Hi,

I have a lot of string texts which normally should only contain a single float so that I can put this float into a variable.
This stings are generated by a grep command out of a large html file.
sometimes a value that I want to grep is found more than once, so that the resulting sting contains the value more than once, too.
Example:
"14.5 14.5"
So my idea was to use the sed command to delete everything after the first found " ". But I am not able to set the parameters for that sed command right.
I hope someone can help me with that...

Thanks,
Stefan

---------- Post updated at 01:14 PM ---------- Previous update was at 01:03 PM ----------

never mind. The Secound after I wrote my question I found the Answer myself:


Code:
sed 's/\s.$//'


Last edited by rbatte1; 1 Week Ago at 09:49 AM.. Reason: Added CODE tags
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago   -   Original Discussion by Stefan Willms
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 January 2018, 3:00 AM EST
Location: Simplicity
Posts: 3,947
Thanks: 335
Thanked 1,322 Times in 1,192 Posts
You certainly meant .* not .$ ?
Further, \s is standard in perl (PCRE). And came into the GNU RE but is not a standard in an RE (not portable to a non-GNU sed).
The standard wants a character class


Code:
sed 's/[[:blank:]].*//'

Last but not least you ask to delete everything *after* a space, that would be


Code:
sed 's/\([[:blank:]]\).*/\1/'

The matching blank is marked in a \( \) group, and the \1 restores it.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete space budz26 UNIX for Dummies Questions & Answers 2 01-31-2012 12:02 PM
Delete newlines after every one space shoaibjameel123 Shell Programming and Scripting 4 10-12-2011 08:03 AM
Delete white space using sed anil8103 Shell Programming and Scripting 3 05-23-2011 08:05 AM
how to delete space character with sed cahyo3074 Shell Programming and Scripting 1 08-14-2008 06:54 AM
How to Delete space from the file deepakpv Shell Programming and Scripting 2 07-29-2008 11:45 PM



All times are GMT -4. The time now is 04:30 AM.