Help with echo and sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with echo and sed
# 1  
Old 11-27-2009
Help with echo and sed

I am using GNU sed but this does not output "what". Why?

Code:
HEY=$(echo "hey 70.70.70.70:21 what: " | sed -nr 's/.*(70.70.70.70\|71.71.71.71):(21\|22\|115\|443\|989\|990) (.*):.*/\3/p')
echo $HEY

# 2  
Old 11-27-2009
Code:
$
$ x=$(echo "hey 70.70.70.70:21 what: " | sed -nr 's/.*(70.70.70.70|71.71.71.71):(21|22|115|443|989|990) (.*):.*/\3/p')
$
$ echo $x
what
$
$

tyler_durden
# 3  
Old 11-27-2009
Thank you Mr. Pitt. I wondered why they were escaped! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example File example; nodegroups: check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com I need to take a file with a one line list of hosts separated by commas host.domain.com,host2.domain.com,host3.domain.comand prepend the string " ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

2. UNIX for Dummies Questions & Answers

What is wrong with: echo $PATH | sed s/:/\\n/g

Hello all! I am on Mac (10.8.4) and my shell tcsh (man says version: Astron 6.17.00). Just to precise my tcsh: echo $LC_CTYPE UTF-8 I want to replace all ':' with a new line, to get all paths on one line. I don't find a way to make my shell accept the "\n" My start was: echo... (17 Replies)
Discussion started by: marek
17 Replies

3. Shell Programming and Scripting

Replacing part of the sentence using echo and sed

Hi, Iam using ksh and trying to execute the following syntax to replace one word of the sentence with a new word. But somehow sed is not able to replace the old value with new value. Please let me know where Iam going wrong. Sample Code : --> export line="VORTEX,abcdef" export... (3 Replies)
Discussion started by: ajithab
3 Replies

4. Shell Programming and Scripting

Sending Sed/Echo output to Variable

I have a variable $WORDS that contains a string Then i want to use sed to break it up. echo $WORDS | sed 's// /g' I tried setting this as a variable by doing WORDS2=`echo $WORDS | sed 's// /g'` But when i do this it does not return me to the prompt properly ie. jmpprd-v1> jmpprd-v1>... (4 Replies)
Discussion started by: nitrobass24
4 Replies

5. Shell Programming and Scripting

Help echo | sed > file

Hello, I am trying to build a very compact script for monitoring FS. I am stuck in a very simple problem (see code comment). Please for your help SERVER_NAME=`uname -n` SCRIPT_DIR=/export/home/scripts/fs_mon4 FLAG_DIR=${SCRIPT_DIR}/flags TEMP_DIR=${SCRIPT_DIR}/tmp FS="\/$"... (1 Reply)
Discussion started by: drbiloukos
1 Replies

6. Shell Programming and Scripting

Problem with variable ECHO $((SED...

Hi, I'm new here so I want to say hello to everyone first! I searched google and this forum for a similar problem, but wasn't successful #! /bin/bash I'm trying to output (echo) n lines of a text file to the screen (later into another file). But I have problem with the sed command, it won't... (1 Reply)
Discussion started by: studiologe
1 Replies

7. Shell Programming and Scripting

echo & sed problems

I need a script to to instert the following line into my postfix master.cf file: flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}if I use echo I get the line truncated: :~ echo flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}... (3 Replies)
Discussion started by: barrydocks
3 Replies

8. UNIX for Dummies Questions & Answers

Having a hard time with the sed/echo commands?

Hello, well what I'm trying to do is to remove underscores from filenames and leaving empty spaces instead: arturas@Universe:/windows/Center/training$ ls big_file failas su shudu arturas@Universe:/windows/Center/training$ a=big_file arturas@Universe:/windows/Center/training$ mv $a `echo... (8 Replies)
Discussion started by: arcelivez
8 Replies

9. Shell Programming and Scripting

Problem regarding Sed/Echo/Var Init

Greetings, I've visited this forums for a long time and normally got an right answer but this time my problem doesn't seem to go away. What I'm trying to do is the following: VAR="\n\nline1\nline2\nline3\nline4\nline5\nline6\nline7\n\n" (The count of newlines is varying!) If I echo this i... (3 Replies)
Discussion started by: ph1l
3 Replies

10. Shell Programming and Scripting

Passing output of sed/echo to a variable

I understand how to use a variable in a sed command, but for the life of me I can't get the output into a variable. I'm making a general function to replace part of a filename with a different string, so: >>myscript this that would change: this_file001.txt to that_file001.txt and... (11 Replies)
Discussion started by: donflamenco
11 Replies
Login or Register to Ask a Question