General :: Bash Script Is Reprinting Part Of A Field From An Awk Statement?

Apr 21, 2010

Here's the bash script:

Code:

FILES="/usr/sbin/accept
/usr/sbin/pwck
/usr/sbin/chroot
/usr/bin/fakefile

[code]....

Notice the extra" file size" lines in there? What's causing that? I'm trying to learn more bash skills. I have no experience with awk because I have been unable to understand it's basic necessity. But I thought maybe if I try it with some test scripts I might become more interested in using it more and expand my very limited capabilities.

View 13 Replies


ADVERTISEMENT

General :: Inverting A Bash Script Statement?

Jul 11, 2010

I want to have the System Bell ring when a process is over say a download. First I created a file named 'beep' that plays the System Bell. Because the System Bell rings by hitting cntrl-G the 'beep' file looks like this.

Code:

echo ^G

I then give the file owner execute permission. I know that this command would serve my purpose.

Code:

[URL]

However I want to sharpen my Bash programming skills. I wanted to write the Bash script along the following logic and with the fewest lines possible. Not really a script, I want to insert this short script via command line instead of a file. Let's say the download has commenced and the PID = 16666.

Code:

until ps -p 16666
do
/root/beep
done

Now obviously 'ps -p 16666' will already evaluate to true. My question is, is there a way to maybe enclose 'ps -p 16666' and prepend some operator that inverts the condition to where until 'ps -p 16666' evaluates to false then run /root/beep?

View 5 Replies View Related

General :: Write A Bash Script Using An If...Then...Else Statement?

May 14, 2010

I need to to write a bash script using an If...Then...Else statement that will accept a day of the week from the command line what do I do or where do I go.

View 2 Replies View Related

General :: Get Part Of A String In Bash ?

Mar 10, 2011

I've a string "this.is.a.name", and I would like to return "is.a.name". How can I do that in bash?

View 3 Replies View Related

General :: Run Part Of A Bash Script From Within Another?

May 4, 2010

I have two scripts, one of which is very long (around 11000 lines), and i need to run this two lines at a time within the other script. Is there any way to do this?

View 2 Replies View Related

General :: Field-terminating Char Appears Within Field Values?

May 18, 2010

I've had a very colorful morning learning the innerparts of Linux's sort command, and have come across yet another issue that I can't seem to find an answer for in the documentation. I'm currently using -t, to indicate that my fields are split by the comma character, but I'm finding that in some of my files, the comma is used (between double-quotes) within values:

Jonathan Sampson,,foo@bar.com,0987654321
"Foobar CEO,","CEO,",ceo@foobar.com,,

How can I use a comma to terminate my fields, but ignore the occurences of it within values? Is this fairly simple, or do I need to re-export all of my data using a more-foreign field-terminator? (Unfortunately, I do not have any control over declaring a different terminator with this particular project).

View 2 Replies View Related

General :: Return Part Of A String In Bash?

Mar 20, 2011

I would like to return the last part of a string in an array of strings in bash.

The array contains in each position the content below:

Code:
a.b.c
a.d.f
a
a.d

[Code].....

View 5 Replies View Related

Programming :: Using If Then Statement Directly In Bash

Aug 12, 2009

When you use an if statement directly in bash you have to put the ";" at the end or not? or am I mixing it with the for loop? I am reading advance bash scripting and it shows the if - then statements without ";" so I need a little clarification here.

View 2 Replies View Related

Ubuntu :: BASH Script: Odd Output Near IF Statement?

May 31, 2010

For some reason, I get said block of errors when I run my script without arguments:

Code:
/home/mark/bin/backup: line 34: [: =: unary operator expected
/home/mark/bin/backup: line 37: [: =: unary operator expected

[code].....

View 5 Replies View Related

Programming :: BASH - Regex In A Case Statement?

Jun 9, 2010

the following works and BASH doesn't complain, but VIM highlights the closing square bracket is if it sees a syntax error. Is there a better way to express regex in a case statement or is this an issue with VIM?

Code:
#!/bin/bash
case $1 in

[code]...

View 3 Replies View Related

Programming :: Escape '*' In Case Statement Bash

Jan 23, 2010

Does it possible to escape * in the case statement

Code:

View 2 Replies View Related

Programming :: Run SQL Update Statement In A For Loop In Bash?

Jun 7, 2010

The script that Iam trying to write is running a for loop and reading line by line from a text file. inside this for loop i would like to execute update SQL statement .

a pesudo code is
Quote:
`$ISQL -U $username -P $Password -D $Dbname -I $INTERFACE <<QRY
for id in $idlist #idlist iam reading from a file

[code]...

View 8 Replies View Related

Ubuntu :: Bash If Statement To Check Installed Applications

Jul 14, 2010

I know with if statements in bash you can do
Code:
if [ $fruit = apple ]
then echo "Good, I like Apples"
fi
But I was wondering if you could do something like this:
Code:
if [apt-cache pkgnames smbfs = smbfs doesn't exist]
the apt-get install smbfs
fi
If so how would you capture the output from apt-cache pkgname smbfs to determine if it's installed?

View 9 Replies View Related

Programming :: Bash - Statement To Check If A File Exists Or Not?

Oct 6, 2010

This script that I found online does the job it promises. it does convert the files to mp3 without an issue. What I need to include now is an if statement that says If $file.mp3 exists then delete $file.wav

Code:
#!/bin/sh
# name of this script: wav2mp3.sh
# wav to mp3
# Credit to the script creator (Nikesh Jauhari):

[Code]...

After that I'm stumped as to how to do the if statement

View 14 Replies View Related

Programming :: Write An If Statement For The First Line Of A Text File Bash?

Feb 15, 2011

At the moment I got my md5sum checking working which I write to a text file and see below.

If the md5sum works it will write the output to check2.md5 test.txt: OK

If the md5sum fails it will write test.txt: FAILED

How do I write if statement to check the output whether or not the md5sum failed or not ?

check1="/home/ops/Desktop/test1/check1.md5"
check2="/home/ops/Desktop/test1/check2.md5"
cd /home/ops/Desktop/test1
md5sum test.txt > $check1

[Code]....

View 2 Replies View Related

Programming :: Shell Script For Adding A Statement In A File After A Particular Statement?

Jun 28, 2010

We are building our C++ project in Kdevelop IDE. Every time we run "Run Configure" from the "Build" menu, a file named "libtool" gets automatically generated. This file contains a statement as "ECHO="echo"".f we run "Automake", without modifying the "libtool" the system hangs and theputer needs to be restarted.Therefore every time we run "Run Configure" we need to include the line "echo="echo"" below the statement "ECHO="echo"" manually.I think a script can be written which does the above on its own.I am not a shell script programmer, I know the good tutorials for shell scripts are available on the net, but learning scripting only for this task would be time-consuming and painful.

View 4 Replies View Related

Programming :: Awk - Print A Field When Field Position Is Unknown ?

Mar 28, 2010

I'm trying to display fields from flat files where the first 8 fields are always the same. Fields 9 - n are varied but will contain specific patterns I'm after. I'm using this so far because "mySearch" is on each line I want to examine.

Code:

How would you pattern match and include 2 additional fields above field $9 but change field position from line to line?

View 12 Replies View Related

Ubuntu :: Matching And Returning A Part Of File Name On Bash?

Apr 25, 2011

If I have files named like this:

abc_one.c
egx_two.c
tsf_two.c

[code]...

View 9 Replies View Related

Programming :: Perl Switch Statement Throwing Error Like Bad Case Statement (invalid Case Value)?

Oct 6, 2010

I've written a simple perl code to learn switches in perl.My code is pasted below,

#!/usr/bin/perl
$opt = 1;
switch($opt) {

[code]...

View 3 Replies View Related

Ubuntu :: (BASH) Join Command (GNU Coreutils) - Why Join Ignores The -e Flag And Fails To Insert FOO In The Empty Field

Mar 2, 2011

I am trying to understand the join command. I wish to join two files:

Code:
$ cat test1
a 0
b 2.51
c 19.85
$ cat test2
a 0
b 2.51
[Code]...

this is great but I do not understand why join ignores the -e flag and fails to insert FOO in the empty field.

View 1 Replies View Related

Programming :: Awk Printing From Nth Field To Last Field

Jan 8, 2010

How can print the, let's say 5nd field to the last field of every record (let's say we have 10 fields)?

I mean: I cant avoid to have to do:

print '{$5 $6 $7 $8 $9 $10}'

View 2 Replies View Related

Programming :: Php - Get A Return From A Field Within A Field?

Apr 27, 2009

I am creating a game with random variables. In the game I have created a dialogue exchange to players. I have set up a table with various returns and I inserted {$fields} to represent various random variables. When I call on the requested fields, I only see the field text and my field names. Am I supposed to parse something and call it back another way?

ie: myfield is: "You have won {$random1} silver! <br />{$wi['gender'] majesty rewards you well." the code I am using to call that field is:

View 11 Replies View Related

Ubuntu Installation :: After Dd From Full 15GB Part To 1.3TB Part, Shows Same Free Space?

Dec 8, 2010

I just used dd to clone a linux partition to a new hard drive, it had 800mb left on the old hard drive, after dd, new hard drive lists 1.29/1.3 terabytes full. Is this what happens by default in dd? How can I fix this?

View 1 Replies View Related

Server :: How To Access Local Part / Domain Part Of Email Address In Postfix's Main.cf?

May 24, 2010

I'm trying to figure out how to access the local part and the domain part of an email address in postfix's main.cf. For example, myname@mydomain.net has myname as the local part and mydomain.net as the domain part.I get the whole email address with %s. I want to speed up the lookups by writing better database queries.I've had no luck finding this in the otherwise well documented postfix.

View 2 Replies View Related

Software :: Server Hosting Different Part Of Web Site Must Appear As Part Of Domain

Jul 13, 2009

we have access to one domain name , 1 internet ip address and may servers hosting different part of site. I want them all to be accessed via same web site . some of the server in our network are embedded devices.they have their specific utility being hosted on that machine. So the severs are bound to be distributed . I just wanted to know how can I access them via single ip, domain name.

View 6 Replies View Related

Programming :: Get A Field Value Corresponding To Another Field Value?

Dec 14, 2010

i have a file : file.dat with following data

Code:

STORAGE PERCENTAGE FLAG:

/storage_01 64% 0
/storage_02 17% 1
/storage_03 10% 0
/storage_04 50% 1

I need to get the value of PERCENTAGE in a variable for a value of storage passed as variable i have tried the following without success like :

Code:

percentage='awk -vx="$defaultStorage" '{FS=OFS=" "}$1==x{print $2}1' file.dat

View 2 Replies View Related

Hardware :: Is CMOSRAM Is Part On Mother Board Or Part Of RAM?

Jan 14, 2010

In bootseqence of linux, the first step is check the CMOSRAM(size 64bytes) setup for custmor setting. So i am just confused wether CMOSRAM is a part of motherboard or is a part of RAM itself.

View 4 Replies View Related

General :: Cd Inside If Than Statement After Fi Back To Old Dir

Jul 12, 2010

the script below prints the pwd of where I want to be. after the fi it puts me back at the original dir. just writing these scripts to understand what's going on.

#! /bin/bash
if
[ -d mydir ]
then
cd mydir/ && pwd
fi

View 4 Replies View Related

General :: If Statement With Multiple Tasks?

Feb 2, 2011

I want to have an if statement that does multiple things:

Code:

if [....] ; then
1=...
2=...

[code]....

View 3 Replies View Related

General :: Keep Last 'n' Characters Of A Specified Field?

Apr 4, 2010

The input file consists of several fields. The first field is always five or more characters long. I want to keep the last five characters of the first field.

Example:
If the input file record is FEDERAL PACIFIC ELECTRIC PRODUCTS then I want to keep DERAL I can do this in four steps by using C, REV, C, and REV again but that seems like doing an easy thing the hard way. Is there a straightforward way to achieve this result with C or some other command?

View 14 Replies View Related







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