Delete rest of line with sed works on Linux but not on Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete rest of line with sed works on Linux but not on Solaris
# 1  
Old 05-18-2010
Delete rest of line with sed works on Linux but not on Solaris

Hi all,

Our application installation uses "sed" command to delete rest of line. It work perfect on Linux but fail on Solaris.
The OS versions are Solaris 9 and Linux Red Hat AS 3.

yourfile.txt
Code:
hello and world
cat and dog
hello world

in linux:
Code:
cat yourfile.txt | sed ‘s/\([^ ]\+\) *and.*/\1/g' > out.txt

then my out.txt look like now

Code:
hello
cat
hello world

=========================
in Solaris

Code:
cat yourfile.txt | sed ‘s/\([^ ]\+\) *and.*/\1/g' > out2.txt

out2.txt
Code:
hello and world
cat and dog
hello world

Any one know why it does not work on Soloris?

Thank very much

Kevin

Moderator's Comments:
Mod Comment
mail address removed, the forums are for the benefit of all, so all Q&A should take place in the forums.

Last edited by Franklin52; 05-18-2010 at 03:53 PM.. Reason: adding code tags
# 2  
Old 05-18-2010
Code:
echo 'hello and world' | sed 's/\([^ ][^ ]*\) *and.*/\1/g'

# 3  
Old 05-18-2010
If this is NOT what you want, explain what you're trying to achieve.
Code:
sed 's/ and.*//' yourfile

# 4  
Old 05-18-2010
Thanks very much , I think it work.

kevin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed works on Linux but fails on Solaris

Hi, On Linux i get the desired ouput: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: Executing the same command on Solaris: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: I need to get the desired output on Solaris i.e. WEB_USER and... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Script works with Linux not with Solaris

Hi I have the following script which works in Linux shell but gives issues with Sun OS Solaris 5.10, What i am trying to achieve here is we have a list of file names in list.txt file and we parse each file at a time for a particular pattern and copt next 4 lines after we hit the pattern to a... (6 Replies)
Discussion started by: Yugendra
6 Replies

3. Shell Programming and Scripting

Find the text in the file and delete the rest of the line.

Hi, I have one requiremnet like this. I need to find some particular string (eg.IncludeDateTime = ) in a file. And wherever it finds the string the unix script has to delete the remaining text coming after the string (ie., 'IncludeDateTime = ' ) in the same line. I tried to write this script in... (5 Replies)
Discussion started by: jannusuresh
5 Replies

4. Shell Programming and Scripting

awk delete/remove rest of line on multiple search pattern

Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum: infile: 64_1535: Delm. = 86 var, aaga 64_1535: Fran. = 57 ex. ccc 64_1639: Feb. = 26 (link). def 64_1817: mar. = 3/4. drz ... (7 Replies)
Discussion started by: sdf
7 Replies

5. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

6. Shell Programming and Scripting

awk -F works on Linux, but not on Solaris

Hello, I found this command works on Linux: $ echo `uptime` | awk -F "load average: " '{ print $2 }' 1.60, 1.53, 1.46 but got error on Solaris: $ echo `uptime` | awk -F "load average: " '{ print $2 }' awk: syntax error near line 1 awk: bailing out near line 1 $ which awk... (2 Replies)
Discussion started by: seafan
2 Replies

7. Shell Programming and Scripting

Find and delete rest of the line

i need to find ' - ' in a line , if i found i need to rest of the line including '-' example libmm-2.0 libytytsunos-5.6 output libmm libytytsunos (7 Replies)
Discussion started by: girija
7 Replies

8. UNIX for Advanced & Expert Users

Delete rest of the line

Hi, can anyone please answer my question in deleting the rest of the line. I have an example below of a file contaning: Serial3/1.5 43.70.195.13 YES NVRAM down down Serial3/3 225.94.155.69 YES NVRAM up down Serial3/6 ... (3 Replies)
Discussion started by: Aejaz
3 Replies

9. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (0 Replies)
Discussion started by: Silverhood
0 Replies

10. Shell Programming and Scripting

Appending line with sed works on Linux but not on Solaris

Hi folks, Our application installation uses "sed" command to append string after specific line or after line number. Both cases work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. i.g: Linux: ----- file foo.txt aaa bbb ccc ddd root#... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question