Problems Using Regular Expression With Sed

ok so im using osx 10.6.8 but i have something with linux on it somewhere I can try this on if that is the problem

I am attempting to take certain parts out of a html file I have figured out how to write a regular expression to specify this data I want to delete using the search funciton in the text editor TextWrangler:

(?<=<div id="right_col">)[\s\S]*(?=</body>)

This works in text wrangler but when I try to use it with sed it gives me errors like this one:

sed: 1: "(?<=<div id="right_col" ...": invalid command code (

I know to use -e to avoid problems with the unix version OSX is based on. The sed is a bit different because its based on an older unix variant but i did that and its still giving me an error. I assume there is something basic I am missing about formatting your regular expression for using with commandline and what characters you can use. I bet it has something to do with the backslashes or the round brackets. normally I would just keep searching till I find the answer but I am bored of this problem. I need to think about something else for awhile. maybe in the meantime someone else can chime in and help me out.


Similar Content



I Am Trying To Run CRCN Protocol In Ns2.31 But Every Time I Am Getting This Error,

Hello guys. When ever i tried to run CRCN protocol i am getting following error:
harsh@ubuntu:~/ns3/test$ ns test1.tcl
num_nodes is set 10
missing operator at _@_
in expression "$i < $val(ni) _@_$val(channum) "
(parsing expression "$i < $val(ni) $val(cha...")
invoked from within
"for {set i 0} {$i < $val(ni) $val(channum) } {incr i} {
$ns_ add-channel $i $chan_($i)
}"
(file "test1.tcl" line 48)

Can someone guide me how to correct this error??

Thank you

Changing XML Property Value

Hi, I am using a XML file in server location which contains some attributes and value.I just want to replace the attribute value inside the tag keeping the complete line and xml file intact. I am looking for Regular expression which can search for attribute name and replace the attribute value with the provided one. Please find below property details.

<server>
<mbean code="com.xyz.domain.wsmq.WSMQConnectionFactory"
name="xyz.qps:service=MQQueueConnectionFactory">
<attribute name="QueueManagerName">QMSTR01</attribute>
<attribute name="HostName">xx.yy.zz.ww</attribute>
<attribute name="Channel">channel01</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>

Regular Expression In Expect Script To Prevent Printing To Screen

Hello, I have an expect script where I ssh to a remote host to determine the network configuration and get from the user the network interface card that should be used. From their response, I determine the subnet mask and save the information to a text file that is later transmitted back to my local host. This is all so that I can set up virtual IP aliasing and verify that the physical IP address of the local and remote host are on the same subnet prior to continuing with the setup. I am running the script on Linux, with expect version 5.45.

The code itelf works just fine, but I'm having some issues with how it displays on the screen. As you'll see below in the example, the default system prompt displays, as does the user input command that I'm sending to the shell from the expect script.

Is there a regular expression or something that I can write to prevent the prompt and command that I'm sending from printing to the screen? I know that it should be suppressed if I have an expect command following the Code:
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r

command, but everything I have tried for strings and regular expressions to expect causes the netstat -rn output to not show up all of a sudden. I'm new to expect, so I'm not really sure why this is happening.

I would really appreciate any help/suggestions. Thanks for your time!

Part of the Script Code:
Code:
expect {
   -re $prompt {   ;# Send individual commands and get user input
        set timeout -1
        
        # Get partner hostname and put in vipsetup.txt file
        send -s "hostname > vipsetup.txt\r"  
        expect -re $prompt
        
        # Display the network routing info for the user and prompt for 
        # network interface card number
        send -s "print \"The network routing table for the $ptner server is displayed below:\n\" ; netstat -rn \r"
        
        expect -re "\r(.*):\r"
        send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r"
        interact "\r" return    ;# Wait for user input from read command
        send -- "\r"
        send -s "echo \$n_card >> vipsetup.txt\r"  
        
        # Obtain subnet mask information for partner based on network 
        # interface card number being used
        send -s "msk=\$(cat /etc/sysconfig/network-scripts/ifcfg-\$n_card | grep NETMASK)\r"
        send -s "msk=\$(echo \${msk#NETMASK=})\r"
        send -s "echo \$msk >> vipsetup.txt\r"
    }
    timeout {
        send_user "Connection to host $hostip timed out."
        exit 6 
    }
    eof {
        send_user "Connection to host $hostip failed."
        exit
    }
}


Script Output:
Code:
The network routing table for the PRIMARY server is displayed below:
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.105.65.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         10.105.65.1     0.0.0.0         UG        0 0          0 eth0
 [root@remotehost root]$
[root@remotehost root]$ ber for this server (i.e. eth0):   '              < 
Enter the network interface card number for this server (i.e. eth0):   eth0

String Concatenation In UNIX / Shell Script

Hi,

I am new to UNIX - i wrote this below script based on the requirement. But i am stuck at the concatenation (at the second last step of the code)

The below code is working fine till the concatenation(second last step) - I need to concatenate Hello to the "physId" e.g. - The filename is UM123456789.20150503 - i am extracting M123456789 and i need to append "HELO" to it at the end. But as per the below script - when i am using the concatenation, it is overwriting the M123456789 and the output thus becomes HELO456789. I am trying to get the output as - M123456789HELO - where am i going wrong?

on the terminal i checked - echo $0 and it gave -> /bin/sh. Hence i wrote the below code.

#!bin/sh
absolutePath=/abc/data/abc_unix/stg/decrypt/*.*
filepath=$(echo ${absolutePath%.*})
echo "$filepath"
filenameext=$(echo ${filepath#/abc*decrypt/})
echo "$filenameext"
file=$(echo ${filenameext#.*})
echo "$file"
extract_physId=$(echo ${file:1:9})
physId=$(echo ${extract_physId})
echo "$physId"
key="$physId"HELO
echo "$key"

Problem With Running Bash Script

Hi

I have just started to use Linux on my Raspberry Pi to host a home automation server & I'm having a problem when trying to run a bash script.

The script in question is to turn off my Viera TV & is as follows
Code:
#!/bin/sh
curl -i \
-H "Accept: text/xml" \
-H "Cache-Control: no-cache" \
-H "Pragma: no-cache" \
-H 'SOAPACTION: "urn:panasonic-com:service:p00NetworkControl:1#X_SendKey"' \
-H "Content-Length: 200" \
-H 'Content-Type: text/xml;charset="utf-8"' \
-X POST --data '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> \
<s:Body> \
<u:X_SendKey xmlns:u="urn:panasonic-com:service:p00NetworkControl:1"> \
<X_KeyEvent>NRC_POWER-ONOFF</X_KeyEvent> \
</u:X_SendKey> \
</s:Body> \
</s:Envelope>' http://192.168.1.87:55000/nrc/control_0/

If I run this from the command line it works fine but when I try to run it from within the Home Automation application it returns error code 32512 which I've seen elsewhere is actually exit status 127 & basically down to not being able to find the program to execute.

Permissions are fine & I've tried using the full path name for both curl and the script itself but I still get the error. Has anyone any idea what I need to change as this looks to be a pure Linux (or rather my misunderstanding of Linux) issue rather than the home automation program

Thanks

Steve

Help Modifying Text With User Input

Hello,

I apologize in advance for my limited UNIX scripting knowledge. I am new to it and really want to learn.

I am trying to write a bash script that updates a config file based on user input.

What is the best method for accomplishing this? I need it to prompt the user for two variables, find the location in the config file, and insert new text with the two variables.

I was thinking I could use sed to find the text in the config file where the new text must be inserted before and replace it with the new text, two variables, and same ending text as before. Example:

echo "1st variable?"
read variable1

echo "2nd variable?"
read variable2

sed -e "s|<the spot in the config file that needs new config>|sometext...$variable2_somemoretext...$variable1\n<the spot in the config file that needs new config>|g" config > config2


This works except variable2 is not inserted into the replace string, only variable1 is. This is the result in config2:

sometext..._somemoretext...$variable1
<the spot in the config file that needs new config>


If anyone can tell me why variable2 isn't working in the sed replace string, or if there's a much better way for accomplishing what I'm after, I'd appreciate any help I can get.

How To Change "-bash-4.1$ "to Regular User Mood User User@

I am new with linux system somehow my regular user mode changed and its became "-bash-4.1$ " also "how to switch root to regular user"? Thanks advance.

Regular Expressions

Is there a program for which you enter a regular expression and it tells you in english what it will perform?

Rsync, Reliable "copy And Paste" Type Of Backup In Case Things Break?

What I did in windows was create images of my drive and restore them.

in linux I am running

Code:
rsync -aAXv --exclude={"/home/*","/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder

and this creates a folder for me with all my files, and apparently saves meta data like permissions and paths...

Since I'm using arch and things break sometimes,I'm booted into a CLI with errors and cannot figure my way out since I'm a noob... would I be able to just delete my entire root and replace it with the rsync backup without a problem?

Remove Write-protected Regular File Without Permission

I wanted to delete a couple of files, so I did. Then I noticed that they were "write-protected". What does that mean? Why was I able to delete the files considering I wasn't the owner and the files did not have group write permission?

Code:
[Michael@devserver backup_database]$ ls -l
total 4344
-rw-r--r--. 1 apache apache   50639 Feb  6 05:42 2015_02_06_05_42_01.sql
-rw-r--r--. 1 apache apache  654623 Feb  6 05:45 2015_02_06_05_45_54.sql
-rw-r--r--. 1 apache apache 3738269 Feb  6 05:49 2015_02_06_05_49_02.sql
[Michael@devserver backup_database]$ rm *
rm: remove write-protected regular file `2015_02_06_05_42_01.sql'? y
rm: remove write-protected regular file `2015_02_06_05_45_54.sql'? y
rm: remove write-protected regular file `2015_02_06_05_49_02.sql'? y
[Michael@devserver backup_database]$ ls -l
total 0
[Michael@devserver backup_database]$