The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple Question aforball UNIX for Dummies Questions & Answers 3 03-04-2008 04:26 PM
sed - simple question scotty_123 Shell Programming and Scripting 13 03-29-2007 02:23 AM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 02:29 PM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM
Simple ksh question frustrated1 Shell Programming and Scripting 1 11-05-2003 12:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-06-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 430
simple sed question

hi
is it possible to cut this two semicolon separated sed commands
echo "string2 string3 string1" | sed s'/string1//g;s/string2//g'
output: " string3 "

to just one sed command without semicolon?

thanks in advance

funksen
  #2 (permalink)  
Old 04-06-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
if what you want is only "string3" ,why not use cut
Code:
 # echo "string2 string3 string1" | cut -d " " -f2
string3
  #3 (permalink)  
Old 04-06-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 430
thanks,

that was just an example, I want to cut out two or more strings out of a line or replace it with any other string I specify

what I want two know is how to combine search strings, like find string1 and string2 and string3 and replace all of them with the same string, and all in the same sed command

like sed 's/string1 AND string2 AND string3/string4/g'
should replace any appearance of string1, string2 and string3 with the same string, string4
which can be in any order in one line, with 100 other strings
hope its clear what I mean
  #4 (permalink)  
Old 04-07-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
funksen,
There are a few ways of doing what you want, but here is one using one sed statement as you requested:
sed -e's/string1/newstring/g' -e's/string2/newstring/g' -e's/string3/newstring/g' input_file
  #5 (permalink)  
Old 04-07-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 430
thanks shell_life

that is almost the same statement that I wrote in the topic, so is there no way to merge this three commands into one with some kind of separator in the first field?
  #6 (permalink)  
Old 04-08-2007
inquirer's Avatar
inquirer inquirer is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 79
Quote:
Originally Posted by funksen
thanks shell_life

that is almost the same statement that I wrote in the topic, so is there no way to merge this three commands into one with some kind of separator in the first field?
echo "string1 string2 string3" | sed "s/string[1-3]/newstring/g"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0