General :: Shell Script For Substitution?

Jul 9, 2011

So, I have 100 folders each of them include a file called script.txt and script2.txt. the file script.txt has and 100include files that have the same name like the folders. So, for example if I have the folders A, B and C then the script.txt will include 3lines such as:

*include A
*include B
*include C

I want for each folder (A, B and C) to create script2.txt which will substitute *include A with $include A, respectively for each folder.

so for folder A, I will have script2.txt

$include A
*include B
*include C

[Code].....

but it is substituting "*" with "$" in each file for all the lines. I think i should probably close earlier a loop.

View 4 Replies


ADVERTISEMENT

General :: Shell Script -- Awk Variable Substitution?

Oct 7, 2010

I have a script in which I'm reading a file line by line and I'm finding certain position value using awk index as

Code:
# 2 spaces before open parens
pos=`echo | awk -v Line="$Line" '{ print index("'"$Line"'"," (")}'`

[code]....

View 2 Replies View Related

Programming :: Shell Scripting Array - Bad Substitution

Jun 19, 2009

I made a little rsync script for log transfer.

Code:
SERVERS=(SERVER1 SERVER2 SERVER3)
SERVER1_SERV=(web ftp mail)
SERVER2_SERV=(web transcoding)
SERVER3_SERV=(web ftp mail)
for SERVER in ${SERVERS[@]}
do
echo "Starting tranfer for server $SERVER"
for SERVICE in ${$SERVER_$SERVICE[@]}
do
something_to_be_done
fi
done
But when I run it I get ${$SERVER_$SERVICE[@]}: bad substitution

View 5 Replies View Related

General :: Sed Substitution Not Working

Jul 26, 2011

I read up on sed and I am confused about it and regular expressions. I am trying to replace some text on one line in a file with some text.

original text: $normal[''];
replaced with: $normal['localhost'];

In my script file file I've tried numerous combinations of delimiters, etc but obviously don't understand all the rules of regular expressions. My current sed command was:

sed -i 's/$normal[''];/$normal['localhost'];/g' /path_to_file
I also saw some examples using variables, so I tried that:
bb1="$normal[''];"
bb2="$normal['localhost'];"
echo $bb1
echo $bb2
sed -i 's/"$bb1"/"$bb2"/g' /path_to_file

In the above test, the echos both show the correct text but nothing happens to the real file.

View 3 Replies View Related

General :: Sed Command Does Not Perform Substitution

Jul 22, 2010

I've been trying to use a find command with -exec to find the differences between identically-named files in different paths. My initial attempt was to do something like this:
Code: find trunk/ -type f -not -path '*.svn*' -exec diff '{}' `echo '{}' | sed 's/^trunk///'` ;

Unfortunately this does not work at all as expected (the diff ends up executing on the same file)! I have narrowed it down to the subshell (inside the ``) but beyond that I have no idea. For some reason the sed, though written correctly, does not perform the substitution. I've changed the diff to echo and played with the sed command and the only way I can get it to perform _any_ substitution is to use .* as the regex. Even s/.*trunk.*/SUB/ doesn't work. Any insight into the inner workings of -exec/subshells/pipes or some crap I'm missing? Don't worry about rewriting the command to make it work; I simply swapped the paths and got rid of the subshell nonsense and everything works fine.

View 4 Replies View Related

General :: Mkdir In Bash Script - Command Substitution

Jun 26, 2010

I was to set up a cronjob that sends its output to a logfile, i want that log file to be unique. the easiest way to set this up would be to make the directory in the script, then output the command to that directory, they call that directory via is full path in cron (because cron only uses full path names.

This does not work

keep in mind the command "/bin/mkdir -p /tmp/pw_log/`date +20%y%m%d_%H%M%S`.log" works fine on the command line - but once I put it in the shell, it does not work.

View 3 Replies View Related

General :: Function Having Background Process Inside Command Substitution

Oct 5, 2010

The first call to "somefunction" works as expected. The function prints "endfunction" and a process in background sleeps 30 seconds. In the second call I thought it should work in the same way, but the script sleeps 30 seconds before it prints "endfunction".Does someone know the reason of this behavior? Is there another way to do a command substitution of a function that has a background process without have to waiting for that process?

View 2 Replies View Related

General :: Determine On System Where Process Substitution Creates FIFO Files?

Aug 16, 2011

I'm writing a C++ application and need to work with process substitution in the Bash shell. I'm trying to find a way to validate the paths passed as arguments to my program, some of which point to FIFO files created by process substitution.

Is there a shell (or C++) way that I can check if the system creates these files in /dev/fd or if they are created somewhere else?

View 2 Replies View Related

General :: Repeatedly Getting Command Substitution - Line 3 - Syntax Error Near Unexpected Token

Aug 31, 2010

I am repeatedly getting error:

I need to pass the value of:

I am using #!/bin/bash

This command works on shell without any issue.

View 8 Replies View Related

General :: $HOME/.bashrc Disabled When User Shell Is 'rbash' (restricted Shell)?

Jun 15, 2011

MACHINE: HP Proliant DL260G5OS: SLES 11 SP1kernel: Linux xserver 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/LinuxIt is used as remote xserver in a LAN.I have configured /usr/lib/restricted/bin/.rbashrc with some environment variables but when the users logon in the system finally is executed $HOME/.bashrc and some environment vars are overwritten.

View 2 Replies View Related

General :: Write A Shell Script Instead Of Shell Function?

Apr 27, 2011

I would like know when it is necessary or advisable to write a shell script instead of shell function ?

View 3 Replies View Related

General :: Open A New Shell From A Shell And Switch Between Them?

Jan 18, 2011

I am wondering if I can open a shell or new terminal thing from within the terminal in a unix/linux enviroment. Particularly a commandline only one where there is no GUI. Is this doable? how do I do it?

View 3 Replies View Related

Ubuntu :: Font Substitution Etc In OpenOffice

Feb 20, 2010

I have to send CVs to people as Word docs. I compose them using Linux Libertine font. This means that if I send them as they are, they will almost certainly be viewed in a completely inappropriate font. I have tried creating a copy converted to Times New Roman, but the result is inferior. I am also uncomfortable with this because I tend to end up with the originals the copies out of sync. I would rather have just one doc file for each type of CV.What I would like to know is:

1. Is there a serif font that all MS Office users are certain to have that is a less scrappy looking alternative to Times New Roman? It doesn't have to look identical to Linux Libertine, but none of the other MS core fonts look right.
2. Is there a way of specifying a generic serif font as a substitution in Word docs created in OpenOffice Writer like there is in HTML?

View 2 Replies View Related

Ubuntu :: Bash Scripting Gives Bad Substitution

Feb 18, 2011

I'm trying to get the substring of a string in bash. Here is the code:
Code:
#! /bin/bash
LOCAL_HOSTNAME=$(hostname)
echo $LOCAL_HOSTNAME
INDEX_OF=`expr index "$LOCAL_HOSTNAME" 1`
echo $INDEX_OF
SERVER_HOSTNAME=${LOCAL_HOSTNAME:0:INDEX_OF}
echo $SERVER_HOSTNAME

It's supposed to get the current hostname, assign it to variable LOCAL_HOSTNAME, get the first occurrence of "1" from hostname and assign value to INDEX_OF, the get the substring from variable LOCAL_HOSTNAME (starting at index 0 through INDEX_OF) and asign it to SERVER_HOSTNAME. No matter how much I've tried it keeps throwing Bad substitution error at the substring. I've searched and it says it has to be bash... but it is bash, both the sh script and the running shell. The LOCAL_HOSTNAME and INDEX_OF variables are ok.

Here is the output:
I've also tried to get the substring without the INDEX_OF but it gives the same error: SERVER_HOSTNAME=${LOCAL_HOSTNAME:0}
Code:
host1
5
test.sh: 7: Bad substitution

View 2 Replies View Related

Ubuntu :: XML Close Tag (RegEx) Substitution (Using Sed)?

Apr 22, 2011

This makes me feel like a total n00b but I'm trying to figure out how to replace an XML close tag (such as </pagenum> ) with the same XML close tag followed by yet another close tag. (I want every occurrence of '</pagenum>' to be replaced with '</pagenum></p>').

I've tried using something like this:
Code:
sed 's/</pagenum>/</pagenum></p>/' old.xml new.xml
What am I missing? Please forgive me. I'm diving head first into RegEx.

View 5 Replies View Related

Programming :: Variable Substitution In BASH?

Feb 17, 2011

Just a simple BASH for loop to read the file path from a text file (clean.txt) echo the variable for debug purposes, and scp it to a server I have using port 50 for SSH.

I've already formatted the entries in clean.txt to handle spaces correctly, using sed replacement.

Example from the clean.txt file:

Code:
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/20 Auld Lang Syne.mp3
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/14 Deck the Stills.mp3

[Code]....

View 5 Replies View Related

Programming :: SH - Recursive Variable Substitution

Jul 1, 2010

I have the following test code fragment:

Code:

When I try to run it 'sh' reports the following message^

Code:

You might understand what I mean with that test code so could you recommend how to achieve the required effect?

View 7 Replies View Related

General :: Sed Substitution Of Variable With A Variable?

Dec 27, 2010

I am trying to alter the character position of residue numbers above 999 in a pdb file.The following script is an attempt to:1) Get all unique pdb residue numbers (in column 5) using awk and assign it to a variable i.2) Loop through all the values in $i and if it is greater than 999, shift that number one character to the right using sed.However, the script only manages to alter the final residue numberCould anyone please advise how I can loop through all values in $i and shift it one character to the right?

#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)

[code]...

View 6 Replies View Related

Debian Configuration :: Error: EOF In Backquote Substitution

May 24, 2010

After apt-get upgrade I get this:

Setting up linux-image-2.6.32-5-amd64 (2.6.32-13).
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-amd64
Running update-grub.
/etc/default/grub: 26: Syntax error: EOF in backquote substitution

[Code]...

View 7 Replies View Related

OpenSUSE :: 11.3 X86-64 Thunderbird 3.0.11 Html Font Substitution

Feb 4, 2011

I have been doing some work on an mailing system and sent a test e-mail to myself. This had an html body and a paragraph for which the font was declared as itc zapf chancery ,cursive. I know this is not a good choice but it was only a test. When displaying the html message in thunderbird, Zapf Chancery was not used and the paragraph displayed in some other font. If I go into preferences -> composition, I can display a list of fonts that includes itc zapf chancery. Thunderbird displays the html page without problems.

View 1 Replies View Related

Programming :: Bash - Why Is Process Substitution <() So Much Faster

Nov 25, 2010

file allids consists of 300,000 rows, each containing a 5-7 digit numeric id. file newids consists of 20,000 rows of id's. How do you explain the following timings? time: 0.07s:

Code:

diff <(sort allids) <(sort newids)
time: 1.6s:

[code].....

View 4 Replies View Related

Programming :: C Wrapper For Secure Password Substitution

Feb 3, 2011

I'm working on a program that will allow non-privileged users the ability to substitute passwords that are read in from a 600-root:root file.
A user might call it like this:
/bin/securepasswrapper "/path/to/check_ping -u Admin -p ?webserver1?"

The file (defined now as /tmp/securefile) will be searched for the identifier "webserver1", and it's corresponding password will be returned to securepasswrapper. Now, I know you could just call /bin/echo, and get the output, but that's in scope at this point.
File format of securefile is:
<identifierassword>
ex: webserver1:asdf123

Once the password is properly substituted in, securepasswrapper should then execute it as the UID/EUID of the calling user (not root)...that part I've not got to yet.
Code:
/* program: securepasswrapper
author: R.Briggs + Google
date: 02/02/11
purpose: C wrapper that replaces placeholders in a string with secure passwords retrieved from a file
*/ .....

View 5 Replies View Related

Programming :: Implement Variable Substitution In Strings?

May 6, 2011

I have an interpteter that supports string literals, and the way it works is that the lexer returns the entire string as a single token, with the quotes removed and escape sequences replaced with the literal characters they represent.

I already implemented single-quote strings, they don't interpret any characters specially except for the single quote. I partially implemented double-quoted strings, they already support all the same backslash escape sequences that C does. But I would also want to add variable substitution.

The way it would work is that "${expression}" would interpret the expression (which could just be a variable name) and replace itself with the result. But I have no idea how to do this.

In case it matters, I'm using a hand-written lexer and recursive-descent parser.

View 14 Replies View Related

Programming :: Sed Substitution - Doesn't Appear To Be Capable Of Resolving Variables

Dec 21, 2008

I have a simple script that I am writing to parse an XML file for me, and update some version numbers. Basically what happens in my script is that I'm running a grep command on the file to get the current version number, then I prompt for a new number, and then I want to globally replace that version number in the file. The problem is, the sed command seems to only want literal values (it doesn't appear to be capable of resolving variables). For example, this code doesn't work:

[Code]...

I have tried removing the curly brackets from the variable names, quoting them, etc. and nothing seems to work. Should I do this with awk instead (and if so can you kindly write out the command for me because I never bothered to learn awk).

View 2 Replies View Related

Programming :: Awk - Substitution With Parts Of Matched Regular Expression Used?

Apr 30, 2011

I remember reading that using sed, you can do this with parentheses: s/abc(something)def/(something)else/g I can't find an explanation of how to do something like this with Awk. Say you have this in an HTML file, where (number) stands for a one or two-digit number:

<sup>(number)</sup>

And you want to change that to this:

<a name="(number)t" href="#(number)b"><sup>(number)</sup></a>

How would this be possible? Would you have to use sed?

View 4 Replies View Related

Programming :: Sed - Match One Line Make A Substitution A Few Lines Down?

Jun 6, 2011

I need a substitution of a particular string (StringA) with another string (StringB). However, there may be more than one occurrence of StringA within the file, but only one instance needs to be changed, which is why I'm trying to be sure of it's positioning against something I know will be unique in the file, and will always have the same distance from the string to be replaced. So, I intend to match on a string (StringC) above the string to be substituted and then have sed go to StringA below and replace with StringB.

So far, I have had some success with the following:

Code:

... but I can't help thinking that there *has* to be a cleaner way of doing it.

View 6 Replies View Related

Programming :: Variable Substitution In Sqlite Open Db Command?

Jun 15, 2010

I have the following TCL code:

if{ [catch {sqlite3 db /path/to/db/file} result] } {
puts stderr $result
} else {
do something
}

What I want is to use a variable for the file name/path. When I put in a variable instead of the absolute path, I get an error: "missing close-brace: possible unbalanced brace in comment while executing"

This is weird because when I run the code with the fully qualified pathname, it works fine. I substitute out the pathname for a variable containing the pathname ($variable) and I get this error.

View 1 Replies View Related

Debian :: /bin/dash: Bad Substitution Shown Repeatedly Until Kill Process

Mar 16, 2011

if i run /bin/dash at the command prompt I get the message /bin/dash: Bad substitution shown repeatedly until I kill the process

View 14 Replies View Related

Programming :: Bash: Functional Difference Between Process Substitution And Here String With $( )

Mar 14, 2010

Further to solved LQ thread Bash: how to populate a list of arbitrarily named files?, what is the functional difference between feeding a loop with process substitution and feeding it with a here string with embedded command substitution? ABSG pages: process substitution, here string and command substitution. This works

Code:

while IFS= read -r -d '' file
do
files+=("$file")
done < <(find $dir -type f -print0)

[code]....

View 2 Replies View Related

Security :: SSH Config - What's To Stop The MIM From Making A Substitution Of Keys During The Initial Exchange

Oct 20, 2010

Ive been running ssh to log into server for long time. Recently a x-win app reported that it suspects a man in the middle attack (MiMA), so I want to tighten this up, but it seems to me if there is a MiM, then the initial key exchange is vulnerable to a substitution. This is on solaris, but since its a basic concept I'm ot getting, it shouldnt matter,

Here's the gist of what I read:

- create users key pair,
- enable host authentication (ssh_config file on client and sshd_config file on remote host)
- start an ssh session and accept the remote hosts key (and I assume the remote host will take client users key and store some where)

Questions:

1. What's to stop the MIM from making a substitution of keys during the initial exchange?? Shouldn't the keys be initially transfered in a more secure fashion??

2. Does the server just accept new keys from any existing user who want to create an ssh session? So if some one knows a username and password (such as the owner of an application they know is running) couldn't they just create their own keypair and have the server accept them?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved