General :: Parse String In Bash Script?

Nov 8, 2009

I have to create a bash script that takes an arbitrary length number from the command line, and add up each individual digit

Ex:
server> myscript.sh 123
server> 1 + 2 + 3 = 6

The problem I'm having is pulling out each character.

Is there a way in bash I can parse the input string for each character? I can't figure out a way to do this.

View 4 Replies


ADVERTISEMENT

General :: Parse A Particular String In Files In Particular Directory And Its Sub-directories?

May 4, 2010

I want linux command to parse a particular string or pattern in files that are in my home directory and its sub-directory.

View 4 Replies View Related

General :: Write A Bash Script To Parse A Text File?

Apr 27, 2011

I want to write a bash script to parse a text file with the following lines and set variables for each line so that I can use them in the rest of the script.

Timestamp=123456789
Company=ABC Company
Server=Server
Recipient=Joe Smith
Email=joe@abc.com

simplest way to read each line one at a time for everything before the =, set that to a variable name with the value equal to everything after the =

View 14 Replies View Related

Programming :: Awk Parse String With Space?

Feb 4, 2010

How to let awk consider a string by double quota as one field? for example:

echo "first "second is a string"" | awk '{ print $2 }'

I want to print out "second is a string".

View 8 Replies View Related

General :: Parse File From Remote Server To Caculate Count Of String Existence In That File?

Aug 30, 2010

I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files.Say a file abc.log exist on 2 servers.I want to search for string "test" on both files and calculate the total count of search string's existence.For example if file abc.log on server 1 has string "test" 2 times
and file abc.log on server 2 has string "test" 4 times.then the output will beStringName : Countexampletest : 6 timesNote : I have created the password less connectivity using ssh-keygen.

View 2 Replies View Related

General :: Bash Script To Parse A File To Get A Set Of Line Between A Specific Characters?

Dec 23, 2010

I have a log file that contains information like this:

----------------------------
r11141 | prasath-palani | 2010-12-23 16:21:24 +0530 (Thu, 23 Dec 2010) | 1 line
Changed paths:
M /projects/
M /projects/

[code]....

what i need is, i need to copy the data given between the "---" to seperate files, for, e.g. the first set of data between the "---" should be in one file and another set of data in another file.

View 5 Replies View Related

Programming :: Read A File And Parse A String In C++

Jul 26, 2010

I need to read a file and parse a string. I know in Perl there is the split command. Is there something similar to that in C++?

View 6 Replies View Related

Programming :: Why Does Strptime (c++) Seem To Not Correctly Parse Date/time String

Feb 8, 2010

here is the problem code using strptime() function.

==================
#include <stdio.h>
#include <string.h>
#include <time.h>

[code]....

Why are the Month and Year so messed up? I am using strptime() according to the man page.

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 :: 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

General :: Split A String Into Array In Bash?

Mar 17, 2011

how do I split a string into an array?In this string:"this is a story"how do I split it by the space?

View 8 Replies View Related

Programming :: Parse XML To Get IP Adresses Only Using Bash

Jul 28, 2010

I got this xml

...
<other stuff="etc">...</other>
<cluster id="1">
<host ipaddress="192.168.50.1" name="server1">
<host ipaddress="192.168.50.2" name="server2">
<host ipaddress="192.168.50.3" name="server3">
</cluster>
...

how would i get the ip addresses only using bash.

View 4 Replies View Related

General :: Environmental Variable In Bash Command String?

Feb 9, 2011

I do this:

Code:

a@b:~$ export A=hi
a@b:~$ echo $A
hi
a@b:~$ bash -c "export A=blah; echo $A"
hi
a@b:~$

Why doesn't the bash command print the new value of $A? Is there a way to make it do so?

View 6 Replies View Related

General :: Evaluation Of Postfix String Using Bash Shell

Mar 15, 2011

I would like to evaluate a postfix string using bash shell script,but I do not know how to start.

View 1 Replies View Related

General :: Change Case Of A String (BASH Scripting)?

Jul 9, 2010

Is there any inbuilt functionality in Unix shell script so that i can able to convert lower case string input to an upper case? I dont want to use high level languages like java,python or perl for doing the job.

View 4 Replies View Related

General :: Pull String From A File Into A Variable Using Bash

Aug 6, 2011

I have a file (.tmpfile) and inside it is a string which i only know part of, the rest being a random group of characters... I would like to know how to pull the whole string out of the file and into a variable.

View 13 Replies View Related

General :: Check If Any Of The Parameters To A Bash Script Match A String?

Sep 8, 2010

I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" != "-disCopperBld"]but there might be a large number of parameters, so I was wondering if there is a better way to do this?EDIT:I tried this chunk of code out, and called the script with the option, -disableVenusBld, but it still prints out "Starting build". Am I doing something wrong?

while [ $# -ne 0 ]
do
arg="$1"

[code]....

View 3 Replies View Related

Programming :: Bash - Parse Apache Log For Requests Per CIDR / 24

Feb 6, 2011

I'm trying to figure out how I can get a request count per CIDR/24 from an apache log in combined format - e.g.:
Code:
24.147.44.122 - frank [10/Oct/2011:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "[URL] "Mozilla/4.08 [en] (Win98; I ;Nav)"

I'm stuck using BASH for this and I generally write everything in Python, or even Perl if necessary so BASH isn't the most comfortable for me. I've got enough to extract the IPs and get a count I just need a slick way to come up with a sum on a per CIDR basis.

View 3 Replies View Related

General :: Bash: Substitute Parameter In A Quoted String - Stored In Another Variable

Jan 31, 2010

(variable substitution?)
(parameter expansion?)
Code:
run_repeatedly()
{
NUM=0
while [ <irrelevant stuff here> ]
[Code]....

run_repeatedly "programX -o "./messy/path/output-$NUM.txt"" The echo inside the loop prints "...-$NUM.txt"; obviously I'm aiming to have bash substitute the iteration number so that I end up with many output files not 1.

View 5 Replies View Related

General :: Split A String Into Array In Bash Return Wrong Size?

Mar 21, 2011

I'm trying to split a string, to later iterate using a for loop like

Code:
for (( i=0; i<5; i++))

But, my script returns an array with the size 1.

Here's the script:

Code:
aver=$(grep "avg" A.txt | awk '{ print $2 }');
a=$(echo $aver | tr " " "
");

[Code]....

View 2 Replies View Related

Programming :: Parse Multiple Variable From Text File With Bash?

Jul 13, 2010

I am trying to think of a logic where my file contains some data I had to read and do some processing. Issue is that file contains data multiple times. For example:

:::::::::::
var1=value1
var2=value2

[code].....

I have to read first paragraph of variables and do some processing and then move on until the end of file. Variable names are same in whole file but for each paragraph the value is different. I can't think of a logic to attain this task. How can I do it? It should be a simple bash script, but I am not able to work out.

View 2 Replies View Related

Ubuntu :: Bash - Putting String In File?

May 28, 2011

OK I have a simple script that does:

Code:
# Create temporary file:
pwFile="~/Tmp/temp.cnf"
echo "$password" > "$pwFile"

But I get an error message:

Code:
~/Tmp/temp.cnf: No such file or directory

View 3 Replies View Related

Programming :: Bash String Splitting Into Array?

Oct 14, 2010

I am using gnu bash 3.2I need to split the string into array like

a=this_is_whole_world.file # split [_.]
I need to split this on _ and . some thing like this
a[0]=this
a[1]=is
a[2]=whole
a[3]=world
a[4]=file

preferable using bash regex. if not sed is also ok.

View 2 Replies View Related

Red Hat / Fedora :: Truncate String In Bash Script?

Mar 16, 2009

I want to write a bash script, which will read two strings: firstname and surname, then the script will generate a username. For example: the user name for "Peter Brown" will be brownp.

My questions are:
1. how can I get first letter from variable $firstname?
2. how can I join the two strings together?

View 2 Replies View Related

Programming :: Bash Concatenating String To Variable ?

Jan 18, 2011

I have a program that loops over each word in a sentence. I need to append a constant to the beginning and end of each word. It works up until the last word on the line.

Code:

Output:

View 4 Replies View Related

Programming :: BASH - If Variable -eq String Not Working ?

Jan 24, 2010

Here is the code:

Code:

How ever when I run this script I get the following error

Quote:

I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work.

View 2 Replies View Related

Programming :: Bash Regex String Extraction?

Jun 10, 2011

Code:
g echo ${mm[$j]}
4 BashNotes

[code]...

View 2 Replies View Related

Programming :: Bash Removing String From File?

Aug 7, 2010

I am trying to remove everything before my string code...

View 9 Replies View Related

Programming :: Using Bash To Append A String To Array?

May 19, 2011

I have the following function that does not iterate through the array I want to be able to do some manipulation on each element in the array[@].it appears the below array has only one item in the array whereas i want the array to have 3 items hence the loop three times printing the message Any ideas why this is not happening ?

function foo() {
name =$1
array=( "$2" )

[code]...

View 5 Replies View Related

Programming :: Copy String A To String B And Change String B With Toupper() And Count The Chars?

Oct 22, 2010

copy string a to string b and change string b with toupper() and count the chars

View 3 Replies View Related







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