General :: Assigning "find" Operation Output To A Variable?

Jan 7, 2011

I am assigning "find" operation output to a variable. I also need to have error info / stderr if nothing is found in the same variable itself.

e.g.

a=`find . -name "hello.txt" -type f`

I do not want any temp files to be in between infact, redirection.

View 5 Replies


ADVERTISEMENT

General :: Sed: Assigning Its Output To A Variable?

Feb 3, 2011

Kernel 2.6.21.5, GNU/Linux (Slackware 12.0).In this script,

Code:
semoi@darkstar:~$ cat rename4.sh
#!/bin/bash
INPUT="k3b_audio_0_04"

[code]...

View 3 Replies View Related

General :: Assigning Value To A Variable In Shell Script?

Nov 22, 2010

Why doesn't "var1=`echo $var2 | grep pattern`" work ?

View 8 Replies View Related

General :: Assigning Query Result Into A Variable/file?

May 25, 2011

I am connecting to MySQL DataBase using shellscript and writing a select statement like select attachmentid from attachments where pageid=10175 I want to store the output of the select statement into a shellvariable or a file. How can i do it using shellscript.

View 4 Replies View Related

Programming :: Assigning Variable Is Messing Up?

Nov 5, 2010

I am trying to run this and was into issues

function() {
node=echo "10.11.12.13" | awk '{split ($0, a, "."); print a[1]}'
}

[code]....

View 1 Replies View Related

Programming :: Assigning A Variable For Later Use In Shell Script ?

May 4, 2010

Using things like awk/sed, but have managed to cobble together what I needed so far without a problem. The only thing I'm struggling with is to assign the content of a particular line as a variable, and then to use it again throughout the file.

For example, if what I want is the first line of the file to become the variable "from1", and then to replace the word "Subject" in the file with the string "Message from [from1]". What I thought would work

I tried a few diff combinations but nothing seems to work. All I get is the terminal hanging indefinitely.

View 3 Replies View Related

Programming :: Assigning Bash Variable With The System Command In Awk?

Mar 1, 2011

I am having all sorts of trouble trying to assign a variable within an awk script with the system command. I know there is a lot of ways around this problem, but for efficiency reasons, I would like to, within my awk script, do something like

system(x=3)

or

system(x=NR)

and, latter on the shell script which calls the awk script, use the variable $x. But nothing is passed to x. I have already tried things like

command = "x=3"
system(command)

and also used a pipeline within the system to pipe it to /bin/sh In fact tried a lot of stuff like that, using $(( )) etc etc etc I can create directories e write to files (yes, i could write to a file and read from there, but I dont think it is efficient, plus I am puzzled).

View 7 Replies View Related

Programming :: Assigning Structure Object's Variable Outside Main() Gives Parse Error

Sep 2, 2010

Kindly take a look at the code below :

Code:
#include <stdio.h>
struct test
{
int i;
int j;

[Code]....

why i am getting this error. I know the error is occuring because i have assigned values to obj.i and obj.j outside main(). But i want to know why do that result in an error. From my part i have created an object 'obj' of stucture 'test' and assigned values to its variables.

View 7 Replies View Related

Programming :: Assigning Output Of A Command To An Array In Perl?

Nov 25, 2010

I am trying to execute a Unix Command in perl and assigning its output to an array:

Code:
@File_List=exec("ls -1 /tmp");
but it is not working. I have tried the perl function system() also but its return code is

[code]...

View 10 Replies View Related

General :: Find The Equivalent Command Of A Gui Operation?

Apr 12, 2010

We often require to find an equivalent text command for any GUI operation. Just as an example we click on a folder (say ABC) from the current directory in order to see the contents of that directory. The equivalent command for it to happen would be->

Code:
cd ABC ls Now the thing is that we often don't know what that equivalent command will be. So I want to know that is there any way out to find it. What I want to do is that I shall perform any operation using mouse in the GUI mode(whatever operation it could be) and then I can see a log file to see what I actually did last(rather what the command would have been if I have worked in the text mode)...

View 1 Replies View Related

General :: Any Way To Store Output Of Command Into Variable?

Mar 3, 2010

I tried using the tail command in my shell script and storing that value in a variable a but an error keeps coming. Is there any other way to store the output of a command into a variable. Cannot Read text from text file and store it in a variable using shell script. The thing is I need a number from the file new.txt and use that number in my script

#!/bin/bash
a = `tail -1 new.txt|head -n 1`
echo $a

View 2 Replies View Related

General :: Assign A Variable To The Output Value Of A Program?

Feb 6, 2011

so i wrote myself a very simple hellworld program in c++

...the usual stuff
int main()
{

[code]...

View 3 Replies View Related

General :: Need To Store Output Of Bitset() In A Variable / Possible In C++?

Mar 5, 2010

I need to store the output of bitset() in a variable ... is it possible in c++?

View 1 Replies View Related

General :: Can't Save Grep Output Into Variable / Solution For This?

Feb 3, 2010

I would like to grep two numbers out of a text file, and divide them.

Here is the script code...

It feels like grep saves a new line too? or what is happening? i simply can't divide them, as it handles the variables as they are empty (and prints the two numbers although they were not printed

View 6 Replies View Related

General :: Does The Output Of The Previous Command Get Stored In Any Variable

Mar 26, 2011

For example, when using bash you can use

Code:

to execute the previous command or

Code:

!<number> to execute the Nth command(use history to see the list). Or you can use

Code:

cd !-2:1

to cd into the value in the first field that was executed 2 commands ago Anyhow, say I run a command and the output is a path. Any way to cd and then some variable where OUTPUT of the previous command was stored? A variable that always stores the OUTPUT of the last command.

View 8 Replies View Related

General :: Storing A Variable In A Shell Script After Awk Output?

Feb 8, 2010

On command line I have no problem storing a variable e.g

Code:

:~/bin$ process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`
:~/bin$ echo $process
26736
:~/bin$

When I try to incorporate this into a shell script I get a blank.

Code:

:~/bin$ cat process_idesk
#!/bin/bash
process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`

[code]....

The process_idesk script has been chmoded to be executable by the user. I'm sure there must be a silly omission on my behalf.

View 3 Replies View Related

General :: Count The Number Of Lines Inside A File And Put The Output Into A Variable?

Feb 1, 2011

i need to count the number of files and put the output into a variable. i used wc -l filename but i couldnt find an option to put the output to variable. example if the number o line is 5, i need the output of echo $x is 5.

View 3 Replies View Related

General :: Create A Single Line Of Output From Multiple Variable Lines Of Input

Feb 3, 2010

I need to create a single line of output from multiple and variable lines of input in a Linux bash shell script.

My input file looks like this:

Where there may be any number of umsecondaryphonenumber lines; if there is not a umsecondaryphonenumber line for a telephonenumber, I don't want to write any output.

So, the output file should look like:

The script I have so far is:

My question is - how do print each of the elements of an array in one record - i.e. what do I put in place of howdoiprintarray?

View 2 Replies View Related

General :: Search A File To Find If Variable Belongs To A Field?

May 18, 2011

I have a file that contains 5 fields and anothen one with two I want to take the value from user and search file1 and if the value exists then write in file2 to the $2 to the line that $1=value

file 1
1:fsdfsd:g:33:fsdf
2:yytgdcf:a:3:sgd
3:tttt:g:67:yujhggfg

[code].....

View 2 Replies View Related

General :: Text Manipulation Find / Replace Variable Efficiency?

Aug 27, 2010

What I have works, but wondering what is the 'right' way to replace the digits with the letters given in this loop? somehow use a case or multiple sed? i thought of a multiple sed or a case but couldn't get it to work

Code:

# ...
bcv=$(echo $line | awk -F" " '{ print $1 }' | sed 's/1/q/g;s/2/w/g;s/3/e/g') # and so on

Code:

while read line
do
bcv=$(echo $line | awk -F" " '{ print $1 }')
if [ $bcv == "" ]

[code].....

View 12 Replies View Related

Programming :: Atomic Variable Versus Atomic Operation

May 19, 2010

have two shared variables a,b which are related to each other.When multiple applications share these shared variables, access to them needs to be an atomic operation, otherwise the relation may break. So to ensure mutual exclusion, I'll put their modification under a critical section protected by lock.

Code:

critical_code
{
P(mutex)
a := something
b := something
V(mutex)
}

Lets say my hardware/OS/compiler supports atomic variables. Then I modified my above code as follows.

Code:

code
{
atomic a := something
atomic b := something
}

Can this code ensure mutual exclusion, when accessed by multiple applications?

View 2 Replies View Related

Programming :: Piping Cat Output To Variable?

Jan 10, 2010

New to ubuntu and shell scripting in general... currently I stored some data into a text file. Right now, I would like to output the data from the text file and store it into a variable. Here's what I have so far:

READ_FILE=$(cat $FILE_NAME)

This definitely works and READ_FILE has the necessary data. However, this command will trigger an output to std output and I will see data on the screen, which is not what I want. I tried:

cat $FILE_NAME | $READ_FILE

and various other variants of this. It does not output to std output but neither does anything gets stored into $READ_FILE. I tried:

cat $FILE_NAME >> $READ_FILE

and it arrived at an error of "ambiguous redirect".

View 12 Replies View Related

Server :: CPIO And Find Operation Not Permitted Errors?

Jun 14, 2011

Below is the oneliner that I am using to exclude all of "." hidden directories within the same directory.

Code:
cd find . -depth ( -wholename ./.* ) -prune -o -print | cpio -oav > /media/caca/extract/full$date.cpio
it works fine but when I extract the files from the full$date.cpio archive it appears to have worked but gives me permission errors:

Code:
cd /media/caca/extract
cpio -ivd < full061411.cpio
cpio: Selection_001.png: Cannot change mode to rw-r--r--: Operation not permitted
Selection_001.png
cpio: Selection_002.png: Cannot change mode to rw-r--r--: Operation not permitted
Selection_002.png

[Code]...

View 4 Replies View Related

General :: Find Description Of Mpstat Output?

Feb 19, 2010

I'm wondering where I can find description of mpstat output?.. I'm talking about the output of all available counters presented by mpstat. For instance:

Code:
$ mpstat -Au
Linux 2.6.31-19-generic (lenovo-S102) 02/19/10 _i686_(2 CPU)
17:32:15 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
17:32:15 all 36.00 0.18 10.39 0.73 0.08 0.03 0.00 0.00 52.60
17:32:15 0 36.81 0.15 11.58 1.14 0.16 0.04 0.00 0.00 50.11
17:32:15 1 35.26 0.22 9.31 0.34 0.00 0.02 0.00 0.00 54.86

[Code]...

View 4 Replies View Related

Ubuntu :: C++ - Can't Pass System Output To Variable ?

Sep 8, 2010

I have a line that looks something like this:

Code:

How do i put its output in a variable?

View 9 Replies View Related

Programming :: Retain The Eol In Bash Variable Or Ssh Output?

Jan 17, 2011

I have to save the result of ssh/grep into a file to keep the eol ("/n"):

ssh $SSH_OPTIONS $USER@$NODE "cd $LOG_DIR; grep -h '$pattern' log.*" > $file

So that when I grep on the local file again later, it can be printed out with original log lines. Otherwise, the log lines will be dropped and lines becomes concatenated into a single line, e.g., if I rewrite the script in this way, echoing the $result is not a good idea..

result=`ssh $SSH_OPTIONS $USER@$NODES "cd $LOG_DIR; grep -h '$pattern' log.*"`

is there some workaround that I can save it to a variable rather than file but still keep the eol? That will simplify my script and don't need to do all those I/Os!

View 3 Replies View Related

Programming :: Java Output Into Bash Variable?

Feb 20, 2011

I have a bash script that calls a java class method. The method returns a string to the linux console when run independently. how can I assign the value from the java method to a variable in a bash script?running the script: java -cp /opt/my_dir/class.method [parameter]

output: my_string if added in a bash script:

read parameter
java -cp /opt/my_dir/class.method [parameter] | read the_output
echo $the_output

the above doesnt work, I also tried unsuccessfully:

the_output=java -cp /opt/my_dir/class.method [parameter]
the_output=`java -cp /opt/my_dir/class.method [parameter]`
java -cp /opt/my_dir/class.method [parameter] 2>&1

How can i get the output stored into the_output variable?

View 6 Replies View Related

Ubuntu :: Cannot Pipe Gdialog Output To Variable / Sort It?

Mar 20, 2010

I'm trying to use the output from gdialog's input box in another command with no success. code...

View 3 Replies View Related

Programming :: Receive Command Output And Store It To A Variable?

Apr 3, 2010

Suppose I want to account number of files beginning with abc , I can use "ls 'abc* | grep abc | wc -l", this will return me a number.
I want to store this number in a variable, say var1, so I tried
1. "ls 'abc* | grep abc | wc -l |read var1", but this didn't work as var1 has no value somehow.
2. var1='ls 'abc* | grep abc | wc -l', this just assign the entire string "ls 'abc* | grep abc | wc -l" to var1, which is not I wanted.

I don't want to store the value to a temporary file and then read the value from that file. I think there should be a direct way to get the value, but don't know how. I know in tcsh, one can just use set var1='ls 'abc* | grep abc | wc -l', but it also doesn't work in bash. Can anyone give any clue about this?

View 5 Replies View Related

General :: Use '{}' To Redirect Output Of A Command Run Through Find's -exec Option?

Jan 10, 2011

I am trying to automate an svnadmin dump command for a backup script, and I want to do something like this:

find /var/svn/* ( ! -name dir -prune ) -type d -exec svnadmin dump {} > {}.svn ;

This seems to work, in that it looks through each svn repository in /var/svn, and runs svnadmin dump on it.

However, the second {} in the exec command doesn't get substituted for the name of the directory being processed. It basically just results a single file named {}.svn.

I suspect that this is because the shell interprets > to end the find command, and it tries redirecting stdout from that command to the file named {}.svn.

View 2 Replies View Related







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