👤
Home Man
Search
Today's Posts
Register

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"

Tags
grep, sed, solved, space

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 01-12-2018
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; 01-12-2018 at 08:49 AM.. Reason: Added CODE tags
# 2  
Old 01-12-2018
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.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed not applying /d "delete line" option escooter87 Shell Programming and Scripting 9 03-10-2017 02:42 PM
Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml" Hiroshi Shell Programming and Scripting 2 02-17-2017 01:06 PM
Find "*.c" and "Makefile" and then delete them with one line yanglei_fage Shell Programming and Scripting 3 07-04-2014 12:27 PM
awk -sed help : forth . to convert to "space" rveri Shell Programming and Scripting 11 03-24-2014 08:22 AM
how to use "cut" or "awk" or "sed" to remove a string timmywong Shell Programming and Scripting 8 02-12-2012 11:55 AM
Delete files older than "x" if directory size is greater than "y" JamesCarter Shell Programming and Scripting 4 02-11-2010 07:41 AM
Unix commands delete all files starting with "X" except "X" itself. HELP!!!!? soccerball Shell Programming and Scripting 2 10-15-2009 07:24 PM
Sed: Delete lines in files that contain other than a-z ,0-9 and "." devlin Shell Programming and Scripting 4 10-04-2009 05:12 PM
cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' harshakusam Shell Programming and Scripting 4 08-25-2009 11:21 AM
Delete lines ending in "_;" using sed turbulence Shell Programming and Scripting 12 01-17-2008 05:51 PM


All times are GMT -4. The time now is 09:14 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?