Programming :: Bash Scripting - Output As Multiple Files?
Jan 26, 2011
I have wrote a 1 line command that parses a file, locates the IP Address in the file and then trims the output the way I want it, and then sorts numerically and by uniqueness and then >> appends to output.txt
I can get all the IP's into 1 file "output.txt", but what I am really looking for is some type of way to create a text file, for each IP it finds labeled xxx.xxx.xxx.xxx.txt and also put that ip address into that file..
xxx.xxx.xxx.xxx = the ip address it finds
View 14 Replies
ADVERTISEMENT
May 19, 2010
My query is i have a.sql , b.sql , c.sql files which needs to be executed using "$ db2 -tvf a.sql"; "$ db2 -tvf b.sql"; "$db2 -tvf c.sql" , script with which i can execute all these sql files in a single shot.
View 4 Replies
View Related
Jul 7, 2010
I have a problem with snmp answers being empty or having spaces.
What I already have:
#get all interface indexes (if you wonder - I'm working for a cable company and different cablemodems have different number and types of interfaces):
The problem is the physical address which is sometimes empty and the description which has spaces. So I'm doing 2 snmpgets which is slower than 1 snmpget (sometimes I have up to 18 interfaces).
I'm trying to explain it a bit simpler.
Interface 5 gives me back the following lines:
Ethernet CPE Interface
Now the first line should go into variable ifadm,
2nd line should go into variable ifoper,
3rd line should go into variable ifspeed,
4th line should go into variable iftype,
5th line (which is empty) should go into variable ifphys and finally
6th line (which has spaces) should go into variable ifdescr
View 4 Replies
View Related
Oct 26, 2010
To redirect standard output to multiple files:
Code:
echo Test | tee file1 file2
My problem is that the word "Test" still displays to the screen? I want same effect as:
Code:
echo Test > file1
but with multiple file redirection.
View 3 Replies
View Related
May 9, 2011
bash script to give sensible names to a large number of photos. I hope to be able to run a script with an argument which will become the filename followed by a number beginning at 1.
Code:
./file_rename.sh Summer2009_
Summer2009_0001
Summer2009_0002
Summer2009_0003
[Code]....
View 1 Replies
View Related
Nov 26, 2008
I have a config file that contains:
my.config:
Code:
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
Here is my parse_cmd script:
Code:
View 3 Replies
View Related
Oct 3, 2009
i have lots of files with dots insde file name for example:
document.1.is.bigger.doc
resume.version12.doc
10.photo.www.cnn.com.jpg
i want to rename all files in that directory to be the same (with same extention) but convert dots to underscore "_"
how can i do that on bash script / php.
View 6 Replies
View Related
Mar 6, 2011
I have this cool bash script that I worked hard on. But it broke down when it can across files that had non-English characters. Another small problem was getting it to descend into a directory. If it renamed a directory it would not descend into that dir to rename the other files. I would have to run the script twice on the same directory.
Here is the script:
Code:
find -type d -o -regextype egrep -iregex '(.*.ogg|.*.mp3|.*.wav)' | while read s
do
rename -v 'y/A-Z/a-z/' "$s"
done
find -type d -o -regextype egrep -iregex '(.*.ogg|.*.mp3|.*.wav)' | while read n
do
rename -v 's/ /_/g' "$n"
done
A French name like this:
Code:
Chateau De Sable (imagine accents above the letter a)
became this:
Code:
ch303242tea_de_sable
This is not what I wanted.
Why would the script not descend into a directory after it was renamed?
View 7 Replies
View Related
Jun 5, 2009
I want to remove duplicate or multiple similar lines from multiple files. I.e. if I have four files file1.txt file2.txt file3.txt and file4.txt and would like to find and remove similar lines from all these files keeping only one line from these similar lines. I only that uniq can be used to remove similar lines from a sorted file.
View 9 Replies
View Related
Jul 8, 2010
I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?
View 2 Replies
View Related
Jan 27, 2010
I'm trying to put together a script that will quickly run through an archive directory of log files that are named by day of the month 01.gz, 02.gz, 03.gz.... 31.gz. The script uses gunzip -c | grep | wc to count up the total number of hourly occurrences of a filename and outputs the results to stdout.
The only snag I have left is the octal limit when it gets to 08 and 09. I've seen examples using perl and awk, but this script uses a number of nested for loops and if statements that I don't want to have to rewrite in a different syntax. I found that I can use num=10#08 to set that variable to a base 10 instead of a base 8, but then I lose the leading 0 again when it passes the number to the next filename variable.
View 8 Replies
View Related
Aug 25, 2015
You are probably using systemd (check it with ps --pid 1) and therefore /etc/init.d isn't considered for autostart. Here can you find some information about systemd and autostart [1]. As far as I know systemd isn't intended to start applications with systemd. I recommend you to use the autostart feature of your window manager or desktop environment or at least the .xinitrc.
[URL] ....
View 7 Replies
View Related
May 7, 2011
looking to write a dependency map tree that creates a tree structure of object names . This tree will be written to a file and read back to create the tree structure of files . how to write this using bash ?
View 1 Replies
View Related
May 29, 2011
I have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range
Code:
#!/bin/bash
p=`cat list.txt | awk '{print$1}'`
[code]....
View 2 Replies
View Related
Jul 6, 2011
I've been using Ubuntu for about 6 months now, but haven't had a need to start scripting until just recently. I know programming basics, but that's about it.Anyway, I have a program that I would normally run in this manner (note that I didn't create a permanent alias because I've been moving the program around a lot):alias dx='python /path/to/dxProgram.py' dx A_input.dx B_input.dxSo, you see, program dx takes two input files, and 'A' must come before 'B'. I have a folder full of these types of files that I'd like to loop through with this program. They're named as follows:
0_A_input.dx
0_B_input.dx
1_A_input.dx
[code]....
View 6 Replies
View Related
Dec 6, 2010
I'm writing a bash script to copy a list of files and do some stuff to them. Basically, I have the code written that does what it needs to do, but I can't quite understand why it works. I was hoping someone could clear up my understanding a bit.
Code:
The first line generates a list of files. I wrap each line in quotes because they usually have spaces in the directory names.
The second line changes IFS, and I understand what IFS itself does. What I don't quite get is what the separator becomes with that echo statement. If I'm reading that correctly, the backspace will remove the newline and essentially the result is nothing? I found this solution on a web page somewhere, but it was years old and there was no real explanation.
View 1 Replies
View Related
May 21, 2011
I need to write a bash script that will allow me to manage my "virtual network" (in reality just a bunch of directories and files). I need to obtain something like : I have my own command 'connect'. We can use it in two different modes: user and admin. If I type 'connect adashiu virtual_machine_name, computer will ask about password, if password is correct he will change a prompt to :
adashiu_at_virtual_machine_name >
after that user can start to use commands reserved only for user mode. Analogically with admin mode: prompt 'admin >' and administrator can only use bunch of commands reserved for him. changing prompt and separated commands for user and admin ?
View 8 Replies
View Related
Feb 23, 2010
I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.
declare -a arr1
arr1=( $(/some/command) )
Supposing it will eventually (after executing the command) have element values as -
arr1[0]=1234
arr1[1]=5678
arr1[2]=7890
Now, I need to declare another set of arrays, one for each of the element values above - e.g.
declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890
And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -
arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"
arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"
I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.
View 7 Replies
View Related
Mar 23, 2011
I need to be able to compare a file date with system date and delete files older than 30 days.
the file name is basically
error_log.03222011
of course the extension is the date the file was created.
Oh and before i get hammered I looked everywhere but am unable to make sense of what I found.
View 3 Replies
View Related
Apr 1, 2010
pretty simple. how would you background a process from a script and get its process id at the same time?
View 6 Replies
View Related
Sep 21, 2010
I am running an application called QuantiSNP [URL]. The binary file is "quantisnp2", called upon in the "run_quantisnp2.sh" supplied by the authors. I am only able to run the application for single file processing (e.g. 1 input file for 1 sample; I can't run the batch file processing because I don't have the necessary BeadStudio report files, which has different formatting for the input files).
The difficulty is that I have 300 samples (300 unique sample IDs) and 3 input files for each sample for a total of 900 runs of this application. I am wondering how would I be able to automate this process as a shell script instead of basically manually changing the sample ID and respective input files every time a run completes? I bolded the single file processing shell script command line options below that need to be changed for each sample/input single file processing run. The command line option "--sampleid" is for the name given to the processed output files corresponding to the sample of interest and there are 3 input files for each sample.
/home2/jason/QuantiSNP/quantisnp/linux64/run_quantisnp2.sh /home2/jason/QuantiSNP/MCR/v79/ --config /home2/jason/QuantiSNP/quantisnp/config/params.dat --levels /home2/jason/QuantiSNP/quantisnp/config/levels-affy.dat --outdir /home2/jason/QuantiSNP/quantisnp_out/ --sampleid sample1 --gender female --input-files /home2/jason/files/sample1_input.txt
Note that each sample has 3 input files, for a total of 3 runs of "quantisnp2" for each sample. e.g.
SAMPLEID INFILE
sample1 /home2/jason/files/sample1_input.txt
sample1 /home2/jason/files/sample1_input2.txt
sample1 /home2/jason/files/sample1_input3.txt
[code]....
View 7 Replies
View Related
May 7, 2011
I am trying to create a custom service to manage a minecraft server what runs in a screen session (this is to allow easy console access as opposed to running it as a nohup background process). I am hitting two main issues with this script so far and wondering if anybody is able to shed some light on it, considering I am far from the greatest BASH scripter on Earth.
The issues are related to start and stop. the first issue with start is there is a command run "screen -dmS minecraft java -Xms1024M -Xmx1024M -jar /minecraft/minecraft.jar nogui" what doesn't appear to work, however when run from console (copy and pasted) this command seems to run perfectly. I am uncertain as to why this is not working within the script. Also if run from a script in /minecraft it also appears to work but in the minecraftd script I have created at /etc/init.d it does not work. I think the issue might be related to the location but am not certain on it, nor how to resolve it.
the second issue with stop is that it works sometimes but at other times it does not, overall it seems to work about 30~50% of the time. When it works it passes a couple of disconnection messages to the screen session and then gives the stop command (the command to gracefully terminate the minecraft server). It seems to work more often when using screen that I attach to the minecraft session while it is running but really not sure if this is an issue with my scripting or an issue with how I am passing things to screen.
The full code in /etc/init.d/minecraftd is below
Code:
#!/bin/bash
## Script Information
## Script Author: Berwick East
[code]....
View 9 Replies
View Related
Jun 15, 2010
I was wondering if there is way to hide passwords in bash scripts. For example: I have to write a script to export a full ldap structure, and I'm using the ldapsearch -y passwordfile, where password file is a plain text file that contains the password. Is there a way to hide the password from that file?
I was thinking to remove the r attribute from the file and before the script is lunched to put the attribute back, but is not a good solution, the same with immutable attribute.
View 7 Replies
View Related
Feb 27, 2011
At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3
View 9 Replies
View Related
Aug 11, 2009
Is there a way to process individual characters one-by-one from a text file in Bash, or is that hoping for a little too much from this lovable old clunker?
View 13 Replies
View Related
Sep 12, 2010
I currently have 3 files with floating point data that I wish to have in a single file with the format:
Code:
F1 F1 F3 Output
a1 b1 c1 a1 b1 c1
a2 b2 c2 a2 b2 c2
a3 b3 c3 a3 b3 c3
a4 b4 c4 a4 b4 c4
View 3 Replies
View Related
Jun 17, 2010
I have a system setup script for my Slackware installations that pulls all packages and source files from another machine and sets everything up to be identical between machines. The script works as expected but make it entirely unattended. How do I make the bash script deal with automatically selecting "Yes" for, for example "Install x(Yes/No): " when prompted by a make file?
View 3 Replies
View Related
Mar 8, 2011
I have a set of files containing data that I need to re-arrange into one single property list.
The files that I have look like this:
Code:
# cat uk
<string>10</string>
<string>11</string>
...
<string>29</string>
[Code]....
So the lines in the files match up but I haven't found a way of reading several files line by line.
View 3 Replies
View Related
Jul 13, 2011
i'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability
View 12 Replies
View Related
Jan 14, 2011
i am using putty to connect to the linux server and i am using nano as my text editor to write a bash script.
this is my script:
echo "Please enter your Username"
read userName
userName= grep $USER /etc/passwd | cut -d: -f5
echo "Welcome " $userName | cat >> output.txt
the problem i have is that when i enter my username, the output (my real name) does not display in the output.txt. instead it displays in putty. so when i run my script in putty it shows the message to enter username and after i enter my username my real name appears below it. i want it to show in the output.txt
View 1 Replies
View Related