Programming :: Retrieving And Organizing Data From Command Output?
Mar 31, 2011
I was messing around with Bash scripting just now and was wondering if there was a way to organize the output of a command into an array. Like the Bash equivalent of the PHP explode() function.
View 3 Replies
ADVERTISEMENT
May 6, 2011
I use Ubuntu 11.04 Natty Narwhal and my wife who is not an Ubuntu convert still uses Microsoft Windows. Recently her ageing PC stopped functioning and she bought a more powerful PC with Windows 7 as the OS. Unfortunately, most of her specialised work software refuses to run on Windows 7, but she still wants / requires access to retrieve information from the old drive which was running (past tense) Windows XP Professional up until recently. Because of her fear of breaking the warranty on her new shiny PC, she won't let me remove the casing and fit the old drive. So, the question is, if I fit her old drive into my Ubuntu machine would it harm either my PC or her hdd? Also, these new SATA drives have no jumper settings (slave/master etc). How do I set it up and how do I get the information from this hdd?
View 2 Replies
View Related
Oct 18, 2010
I've got lines of data in the following format:
space1=number of times error has occured
space2=IP address
space3=Error
I've set this out nicely with printf and made it email me, the problem is - it's not entirely clear what each column/space is and the IP and occurances can sometimes seem confusing. Is there any (easy) way to output this into an ascii like table? There will always be 5 occurances, and the format will always be the same
View 1 Replies
View Related
Oct 20, 2010
I am using gtk to program GUI. How can I show the output of shell command into a textbox, ex ps -efc command ?
View 3 Replies
View Related
Jul 4, 2011
My laptop was damaged a couple of months ago. Just a short drop from the couch, but it was hard enough to make the HD inaccessible. I took it to a local, respected shop but they couldn't save any of the data and simply installed a new HD after consulting me.
I have the old drive and would still like to retrieve the data, if the price is right. What should I ask about when looking for another repair shop?
View 4 Replies
View Related
Oct 26, 2009
basically the situation I'm in is someone mistakenly expanded an NAS without unmounting the drive on the server. This corrupted the superblock and its apparent that all the backups are no good. The drive in question was expanded from about 800gigs to 1.8TBs, its done via an NAS.
At this point I'm most concerned about getting the files off the drive, I can deal with resetting the file system but I really need those files. This happened within a week of me joining this group so I'm kind of doing damage control here, backups were not taken of this particular drive.
View 1 Replies
View Related
Aug 23, 2010
I am trying to develop a method of reading files generated by other programs. I am trying to find the most versatile approach. I have been trying bash, and have been making good progress with sed, however I was wondering if there was a "standard" approach to this sort of thing. The main features I would like to implement concern reading finding strings based on various forms of context and storing them to variables and/or arrays. Here are the most general tasks:
a) Read the first word(or floating point) that comes after a given string (solved in another thread)
b) Read the nth line after a given string
c) Read all text between two given strings
d) Save the output of task a), task b) or task c) (above) into an array if the "given string(s)" is/are not unique.
e)Read text between two non-unique strings i.e. text between the nth occurrence of string1 and the mth occurrence of string2
As far as I can tell, those five scripts should be able to parse just about any text pattern. I am by no means fluent in these languages. But I could use a starting point. My main concern is speed. I intend to use these scripts in a program that reads and writes hundreds of input and output files--each with a different value of some parameter(s).
The files will most likely be no more than a few dozen lines, but I can think of some applications that could generate a few hundred lines. I have the input file generator down pretty well. Parsing the output is quite a bit trickier. And, of course, the option for parallelization will be very desirable for many practical applications.
View 14 Replies
View Related
Jun 13, 2010
The output of a command changed and I need to extract the data and print it out in a different fassion:
Code:
abcd1=aaaa xx
abcd 2 aaa xx bbb
abcd2=aaaa xy
ab 2 xx aaa bbb ccc xxx
should be transformed to:
[Code]...
Currently I used sed "search1|search2|search3" to get the lines that need to be transformed. But I also need to search for substrings in those lines and I need to print those substrings in a specific order together with other characters. How is this done with sed?
View 7 Replies
View Related
Mar 9, 2011
I am trying to grep multiple numbers from file, grep does have the -f option for that.
Code: grep -f <`seq 500 520` /etc/passwd I know this could be done with
Code: for i in `seq 500 520`; do grep "$i" /etc/passwd; done But my question is fare more behind this example. It is possible to redirect one command output which will be treat as a content of file for another command ?
View 2 Replies
View Related
Jan 25, 2011
I try to write script and echo two command at the same line .
echo "A"
echo "B"
How can I pipe above two command at the same line in text file . So, in the output text file , you can see below ? Code: A B not Code: A B
View 4 Replies
View Related
Jul 14, 2010
I'm troubleshooting a batch of scripts I'm modifying, including an IDL script called by a .csh script. the IDL scripts were provided to me by a coworker and my .csh script is intended to automate a lengthy set of extremely tedious and time consuming processing tasks.
I am currently in the process of debugging, and can't get the IDL to print any messages other than critical failures to the screen. Is there any easy way to redirect the stdout to either a logfile or the screen?
View 2 Replies
View Related
Sep 7, 2010
While making a shell ,there is the following problem Im facing:
I am expecting the user to enter commands in the following format :
I am to separate these and the output of ls -l should be given as input to grep and the output of both to more.
But I am allowed (by our instructor) to use dup/dup2 or any other command(but not pipe or tees).
How to connect the file descriptors after successful execution of each command?
View 5 Replies
View Related
May 15, 2010
I have found this from a site [url]
Code:
But it does not work for me, segfault.
View 7 Replies
View Related
Jan 20, 2011
I need to find one RUNNING word in latest created logs.
and as soon as i will get RUNNING WORD , i have to execute another Unix Command.
I wrote following script code...
View 3 Replies
View Related
Nov 18, 2010
After typing "man cut" in my terminal I can't seem to find this answer.
I am trying to write several shell scripts and want to remove the 'lp:<package name>' from the beginning of each line of the output of "bzr ls" as well as any notices at the beginning of the output, leaving only file and folder paths.
View 6 Replies
View Related
Mar 24, 2011
I am trying to process a column separated data file, with a few bash command. For example, I have
Code:
file1 aaaa yes
file2 aaaa no
file3 bbbb yes
Let say I want to create new file with the output of first column and do something else with the output of 3rd column. Of course there are many ways to process this data file, but I wish to know by using awk, how could I do it. I'm trying:
Code:
awk '{system("touch $1")}' datafile
but the shell command will not able to get the awk '$1' output. How do I get this done ? And for another question, if the data file contains the variable name of a shell variable, how could I make use of it during a awk output ? For example I have a datafile1:
Code:
server1 yes
server2 no
And in another server declaration data file, I got this datafile2:
Code:
server1=xxx1
server2=yyy1
And in my awk script, I want to achieve something like (the syntax is definitely wrong, just to demonstrate what I assume it will like):
[code]....
View 12 Replies
View Related
Jun 29, 2011
I'm doing a project demonstrating weaknesses in facebook's security setup, and I've reached a bit of a roadblock.I need to retrieve the public RSA key of the website (facebook) that it uses for https traffic. I know I can do this through firefox and everything, but I need to do it through the command line. If that's possible, that would be great, and would lead me to question number two. Once I have the public key, how would I use it to decrypt raw network traffic, like from wireshark, that came from facebooks servers that was encrypted using the public key?
View 4 Replies
View Related
Mar 17, 2011
Allow me to submit that i did a mistake of not saving the work which i done in the past few months. i have used history command to see the previous commands. But trouble is that since i had worked a lot on gnome-terminal, only last 1000 commands are shown. Is it possible to see list of all the previous commands for all users. Also, sorry if this sounds absurd, but is it possible to save the details of a session onto a single file ? I not sure but when i had worked on vector Linux, i had used some command to save sessions at the terminal. Is there any analogous command in Ubuntu 10.04 also ?
View 2 Replies
View Related
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
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
Mar 26, 2010
I'm trying to pull out sections from a bunch of files. For one file, I use:
Code:
sed '/string1/,/string2/ !d' <filename.ext >newfilename.ext
to pull out everything between two strings in the original file and put them in a new file.
[code]....
View 3 Replies
View Related
Sep 12, 2010
Is it possible to organize bash script output of which is like on top command i.e. monitoring every let's say 1 sec and old information would cleared?
View 3 Replies
View Related
Mar 18, 2010
Here is what I am doing I have a file, a.txt for example, with following contents:
Code:
coreutils install
cpio install
cpp install
cpp-4.3 install
dbus install
[Code]...
So it seems like the sorting algo. for dpkg --get-selections is different than sorting algo. of 'sort' command when it encounters "-" (hyphen). How can I sort the original file (a.txt) in such a way that it produces the output file ,b.txt, exactly the same.
View 6 Replies
View Related
Feb 5, 2010
how shall I print each variable separately using a generalized form. I tried writing the following within a for loop...Code:echo $(echo a$(echo $i)$(echo $j))which did yield no result. So what shall I write??
View 3 Replies
View Related
Feb 13, 2010
I have a command which generates the following output:
Code:
$ sudo vnconfig -l
vnd0: not in use
[code]...
View 6 Replies
View Related
May 3, 2010
I want to know that is there any method to grep a particular data from a file without using the "cat --- | grep ' ' " command....I need to use a system call for this functionality.
View 1 Replies
View Related
Jan 26, 2011
I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct
So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/
Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.
View 5 Replies
View Related
May 3, 2010
I download some movies those are with 'mkv' , but couldn't be played, I tried other players , like mplayer , dragon , xine, even swich OS to windows , didn't work . not all of those files , but some of them. one of them named 'the.other.man', 2GB.I opened a terminal and executed "file the.other.man.mkv "utput is "data", and command 'strings the.other.man.mkv", output like as follow:
T5}.
S!e
I|
[code]...
View 1 Replies
View Related
Nov 11, 2010
We make everyday a DB Mysql backup on Linux redhat Enterprise. We are using a bash shell script (and putting it in the crontab) to execute it automatically everyday. We added a line to this script telling, once the backup has completed, to find old backup files (stored on hard disk after each backup) older than x days to remove them. We use the find command (search for file type) with the mtime option and in combination with rm command. Everything runs ok but we also want to add some new code to the same line: If find command cannot find anything or fails, for example if it cannot delete file or fails, send the error message (standard error output) to an error file (like error000001 and increasing) and mail the errorxxxx file to an email address for example to admin@companyname.com. What would be the code for this issue to add it to our find command in the same bash shell script??
View 2 Replies
View Related
Jan 21, 2011
In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save the output of time command in a variable. The format of the command is like "time ls -R /opt" Going further, the o/p of 'time' command is:
real 0m0.003s
user 0m0.004s
sys 0m0.000s
Here, in my script, I would like to use only middle line "user 0m0.004s" saved to the variable but unable to find out the way.
View 1 Replies
View Related