Ubuntu :: Using Variables In Awk IF Statements?
Nov 2, 2010
I have a list of names (testnames.txt) and I have a set of log files (testlogdata.log). I'm trying to search the column in my log file for each of the names in my testnames.txt file, and output the result to individual files, name1.txt, name2.txt, name3.txt, etc the names in the column of my log file can appear in different formats , ie the name "Tom Smith" can appear as "tom_smith", "tom-smith", "ACME/tom.smith", "ACME/thomas.smith". etc. To allow for the variations, I have my names in the testnames.txt as expressions, ie, for tom smith, I use the expression "to.*smith", etc.I'm running the following command:
for i in $(cat testnames.txt); do awk '{if ($9~/$i/) print $0}' testlogdata.log > $ioutput.log; done
I want the command to read a value for i, insert it into the if ($9~/inserted value for i/, and dump each line from testlogdata.log into a file named <value-for-i>output.log.
View 4 Replies
ADVERTISEMENT
Apr 6, 2011
mkvmerge -o <filename without extension>_TV.mkv -S <filename> && mkvextract tracks <filename> 3:<filename without extension>.*** && perl /home/brian/Desktop/ass2srt.pl <filename without extension>.*** && rm <filename without extension>.***
Doing these commands for multiple command line file inputs is the goal. So I can just type ./script.sh *.mkv in my terminal.This is what I have so far, but it doesn't work whatsoever.
View 2 Replies
View Related
Oct 21, 2010
I for the life of me is having a hard time with some scripting in Dash with branching statements. What the heck? I read many tutorials all over the net and none of the codes work. They suggest all sorts of variations, but it ain't working for me. Can anyone tell me why the code below always return "Y"?
Code:
#!/bin/sh
clear
echo -n "---> Enter Y or N? "
read answer
if [ "$answer"="Y" ] ; then
[Code]...
Perhaps someone can give me a short explanation on how if statements work? So far my linux experience has been nothing, but a frustrating mess.
View 4 Replies
View Related
May 21, 2010
I have made some modifications to the init script that runs when my PC boots to take me to a /bin/sh shell so I can run some custom scripts. When I exit from here the init statement should mount the root file system and switch_root to it. This all works correctly however the same init statement will be run on two types of pc's and the address of the root fs is different between them. On one PC it sits on /dev/sda1 and on the other /dev/hda1. To select the appropriate addresses I used dmesg to find out if it was the i5 PC and if/else statements to select the right hard drive location.
When I try use a if/else statement in the init script it ends up preforming both the if and the else code. Is there any reason the if else statements wouldn't work the exact same in the init script (it's all shell scripts isn't it?
[Code]...
View 3 Replies
View Related
Oct 7, 2009
I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a jist of what I'm attempting, below.
1. Copy file to be processed (one file at a time, from a list of 10 files in the folder ).
Code:
for i in *
do
cp $i /home/temp
2 . Create a snapshot(n) table : Initialize n = 1
Code:
create table test insert account_no, balance from records_all; -- creates my snapshot table and inserts records in SQL
3. Checking if the table has been created successfully:
Code:
select count(*) from snapshot1 -- query out the number of records in the table -- always fixed, say at 400000
Code:
if( select count(*) from snapshot(n) = 400000 )
echo " table creation successful.. proceed to the next step "
else
echo " problem creating table, exiting the script .. "
4. If table creation is successful,
Code:
echo " select max(value) from results_all " -- printing the max value to console
[code]....
View 7 Replies
View Related
Sep 4, 2010
while learning to write bash scripts, i decided to write some script that, given an integer as input, will tell you the square root of that integer (provided the integer in question is a perfect square). i have already done on using primarily if statements and a while loop. i decided that using a case statement would be a lot simpler and i would be able to make the script more functional. here is what i have so far
[Code]....
i have tried all posible combos of using -ge or >= but i get pretty much the same thing.
the idea is, for now, if the input is greater than or equal to 0 that it will echo test. can you do this sort of thing with case statements? or will it only work if i give it specific values like [1-9] (if this is the case then i dont think the case statement will work for what i want to do)
View 4 Replies
View Related
Feb 5, 2011
I cannot seem to get if else statements to work. if $choice == Dog then i want it to say "you selected Dog" The variable choice has the value Dog in it as proved at the end by echo "yes $choice is $choice" following the error Code: ./test.sh: 37: [$choice: not found How do i get the conditional statement to work? What's wrong here? This is the full script:
Code:
#! /bin/sh
: ${DIALOG=dialog}
: ${DIALOG_OK=0}
[code]....
View 7 Replies
View Related
Aug 11, 2010
I'm writing an if statement where a variable is a number such as 14.05 (this is actually a temperature) and I want to compare it to a predefined value, sample code below:
Code:
I have all sorts of errors regardless of how I do this (double quotes, square brackets). The best idea I've had is stripping off the decimal place so it's a 4 digit number (e.g warning=1503 and DEV_TMP=1405) however this seems a little unnescessary and I'm sure there's an easier way of achieving the same thing.
View 11 Replies
View Related
Jun 9, 2010
I am using C++ with SQLite db in a program that will read read a sub set of records, compare records and write different records to another database. I have a SQLite book, but it only shows examples for the C API. Anyone have code samples in C++ for the following:
Open database
Close
Select *
Read
Write
Or, just show me how to execute a SQL statement with C++ and I can then figure out the various SQL statements I need.
View 5 Replies
View Related
Mar 12, 2011
comparing multiple items or conditions using 'if' statements? I want to do something if one or more conditions is true, for example:
If a = 1 or b = 1.
I've tried:
[Code]...
View 5 Replies
View Related
Aug 27, 2010
I'm have been tasked with created a base Ubuntu image that can be used for cloning to multiple machines. As this is a network environment, each hostname will obviously need to be unique. Rather than manually changing the hostname each time a new, cloned machine is rolled out, I was wondering if there is a way to use a variable in the hostname (i.e., use a variable to truncate the the last 6 digits of the MAC address to the end of the static hostname--or any other unique variable for that matter--so it would look like hostname00E6D4).
View 7 Replies
View Related
Feb 11, 2011
Turns out I don't have bc in my Ubuntu distro and I can't install it. how to subtract two variables (BASH variables) from awk and set the result as another variable, e.g: finalvalue=`awk '{print $first - $second}'`
View 2 Replies
View Related
Mar 24, 2010
I am trying to use bash 'printf' to format an environment variable.Doing this I get on the screen just the format I need (underscores mean blank spaces):prompt> printf "%10s" "1.23"________1.23Unfortunately, when this is assigned to a variable, the format disappears:prompt> X=`printf "%10s" "1.23"`prompt> echo $X1.23Does anyone know what can be done in this case to get a proper format?Why does not 'printf' respect the left blank spaces when assigning values to a variable?
View 3 Replies
View Related
Jun 20, 2011
I have what I hope is a fairly simple question to answer. In my ~/.bashrc file I can create this alias:
Code:
alias uChmodDP='chmod -R $1 $2' #specify permissions. and the variables work fine. But I cannot seem to get any love from this alias:
Code:
alias umnt='umount /dev/$1' I realize the likely problem is the variable following hot on the heels of a specific directory, but is there anyway to specify a variable in an alias like this? For some reason I cannot umount usb pen drives by right clicking, and have to always resort to the terminal to do so, which for me is no real biggie, but if I could create this alias it would be an even better no biggie to umount using the terminal.
Actually, the inability to right click to umount usb devices seems to be a Thunar issue since I run xubuntu. Using Nautilus I am able to right click and eject/safely remove devices. Using Thunar however, right click unmount always pukes back an error that the device must have been mounted on the command line or some such BS. But like I said it is no real biggie to use terminal, but an alias would be even nicer. I prefer using Thunar and Xubu most of the time b/c my laptop is quite underpowered.
View 3 Replies
View Related
Jun 2, 2010
I know many people have asked about environment variables before, but I am having a hard time dealing with these paths while ensuring I don't mess around with the original settings. How would you go about executing these commands in Ubuntu in terms of environment variables?
put /home/stanley/Downloads/ns-allinone-2.34/bin:/home/stanley/Downloads ns-allinone-2.34/tcl8.4.18/unix:/home/stanley/Downloads/ns-allinone-2.34/tk8.4.18/unixinto your PATH environment; so that you'll be able to run itm/tclsh wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put
/home/stanley/Downloads/ns-allinone-2.34/otcl-1.13,
/home/stanley/Downloads/ns-allinone-2.34/lib,
into your LD_LIBRARY_PATH environment variable.
[Code]....
View 1 Replies
View Related
Feb 12, 2010
In terminal, I use the command " export XXX="xxx" " to create a new environment variable, and then " env | grep XXX " to check if it is existed. But when I run the terminal again, the variable I created is disappeared. I've found it just can't save the variables I created..
View 3 Replies
View Related
Mar 15, 2010
I can't seem to find how to export a variable to all processes I run under my user? I have an application that needs this variable, and currently I have to manually export this variable (typing "export VAR=... in terminal) every time before I run the application.
Which profile file I have to put the export expression into? I want all processes to inherit this variable, not just the shell/terminal. I.e. a true environment variable...
View 7 Replies
View Related
Mar 29, 2010
With my .conkyrc. Whenever I output the values of any of the mixer variables, eg. mixer, mixerbar, mixerl, mixerlbar, mixerr, mixerrbar - the correct value is initially displayed but it only persists for one iteration of conky. As soon as conky refreshes (2 secs. in my case), the value goes to zero (0). I'd have to restart conky in order to get another reading until conky loops/refreshes again.
I'm sure that it's not normal behavior because nothing else in conky seems to work this way. Has anyone come across this? I couldn't find a mention of it anywhere.
View 5 Replies
View Related
Apr 7, 2010
I've created a new environment variable and updated another one (PATH). I just want to save this changes once after reboot and forever. This is because I want to run a program (tecplot) just typing 'tec360' in the command line. If I create those new variable ( TEC_360_2008=/usr/tec360_2008 ) and update the PATH variable ( export PATH=$PATH:$TEC_360_2008/bin ) then bash detect the command 'tec360' and it runs my program. The problem is that this changes are not saved after rebooting.
According to the manual, I have to update the .bash_profile in my home directory but I don't have this file in this directory (neither in other directory). I only have .bash_history, .bash_logout and .bashrc in the home directory. I have updated .bashrc (typing . ./.bashrc) but it is not working.
View 5 Replies
View Related
May 13, 2010
I need to set some custom environment variables.
View 6 Replies
View Related
Jul 19, 2010
When I execute something with sudo, the environment that it executes in doesn't have all the environment variables from /etc/profile{,.d/} defined. I googled around and found that there is a way to get the environment variables from the calling environment to be carried over to sudo's own environment, but that's not exactly what I want. I just want sudo to read the /etc/profile and /etc/profile.d/ before executing commands.
View 2 Replies
View Related
Mar 27, 2011
"Once upon a time", I think heard of a way to use variables in the url field in firefox(or maybe it was ubuntu in general?).Anyways, if one would type, for instance, "google pokemon," the url would be changed to
View 2 Replies
View Related
Apr 28, 2011
I'm having a strange problem. I'm using Ubuntu server 10.04 LTS and I want to setup a system with 2 network interfaces: eth0 and eth1. However eth1 does not come up at boot I have a screenshot of my /etc/network/interfaces file I don't see what is wrong. eth0 gets it's adress from DHCP eth1 gets a static adress. When i try to restart networking it quits with this message "don't seem to be have all the variables for eth1 inet" Can anyone point out what I'm doing wrong? if i do 'sudo ifconfig eth1 192.168.3.1 netmask 255.255.255.0 up' eth1 comes up
View 3 Replies
View Related
May 9, 2011
Does anyone know what file I have to modify to set the environment variables for FSCK? I can't run FSCK on my file system because it runs out of memory after about 10 minutes. This variable sounds like it will solve all of my problems but I can't find the file to modify to set the variable or what parameters it takes (number? yes/no?, etc).I'm trying to recover has a lot of information on it that I would really like to get back.
View 4 Replies
View Related
Jun 9, 2011
I want to be able to grab some text from a directory listing in a bash script, and then apply that text to future commands in the same script. For instance, say I do "ls -lais /media/Movies" and get:
2147560409 712544 -rwxr-x--- 1 root users 729645056 1999-03-07 11:45 Young Guns (1987).avi
2147560410 712400 -rwxr-x--- 1 root users 729497600 2002-01-09 01:11 Young Guns II (1990).avi
Then say I want to grab the year from this output and then use that information as part of the command to modify the file timestamp, such as:
touch "Young Guns (1987).avi" -t 198701011200
touch "Young Guns II (1990).avi" -t 199001011200
So that the result of ls -lais is:
2147560409 712544 -rwxr-x--- 1 root users 729645056 1987-01-01 12:00 Young Guns (1987).avi
2147560410 712400 -rwxr-x--- 1 root users 729497600 1990-01-01 12:00 Young Guns II (1990).avi
Anyway, that's just one example, but I often find myself needing to do this type of thing, and I'm sure its possible, just not really done enough scripting recently to know how to do it.
View 5 Replies
View Related
Jul 4, 2011
I always have to google about setting environment path variables when I install new software. My basic problem is that I dont know whether these variables need to be set globally or not. I have read a number of mails/tutorials which say that Environment variables should be set by simply doing an export ..eg EDITOR=nano export EDITOR
additionally I have read that it should be written into /etc/bash.bashrc
But are these really global variables or local? I want the variables to be set
even after I have logged out.
so I could also write the variable here...
/etc/environment
or here
/etc/profile
View 1 Replies
View Related
Jul 25, 2011
I'm trying to write a bash script, and for some reason Bash doesn't seem to like any of my variables _except_ the one used in a loop.What's going on? The same problem with MYS occurs regardless of its name, whether it is declared or referenced before, after, or inside the loop, and whether it is a string, integer, or floating-point number. Also, as far as I can tell, everything related to Bash is up to date.
View 7 Replies
View Related
Jul 26, 2011
I am trying to use the following bash alias:
I've been able to get this working under mac and solaris.
I've also tried not escaping the vars.
Anyone know if this is doable with ubuntu's bash shell? (or any meaningful workaround other than writing a script for this?)
View 2 Replies
View Related
Dec 24, 2010
I have installed ubuntu10.04 LTS in VirtualBox in my home computer(i forgot to tell you i am very new to linux-though i am studying a lot, but....-maybe because of my age "45" i am going slow. LOL. I hope i dont have a heart attack before i finish what i am trying to do in the server). Back to my issue: What i want is to have in the server some enviromental variables running not only for the root user but for all the users,when the server is open and not having to type the following commands every single time i open the terminal. Here are the commands:
export JAVA_HOME=/opt/java
export PATH=$JAVA_HOME/bin:$PATH
export M2_HOME=/opt/maven/maven
export PATH=$M2_HOME/bin:$PATH
[code]....
(where java, maven, tomcat are symbolic links for java jdk, maven and apache-tomcat 5.5.31). Please (LOL) save me from the heart attack, give me the chance to enjoy the holidays with my family!
View 4 Replies
View Related
Feb 19, 2010
I created variables in python and would like to be able to incorporate those into bash commands that will be mixed into the script. Example:
Code:
name=raw_input("Type your name and press ENTER: ")
import os
os.system( echo "name")
Of course this doesn't actually work, but i think you get an indication of what I am trying to do.
View 1 Replies
View Related