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


ADVERTISEMENT

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 :: 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 :: C - Put A Specific Arbitrary Part Of A String Into It's Own String?

Apr 18, 2010

So if I'm given a location of a file like:

How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.

View 9 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 :: 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 View Related

Software :: [sed] Returns Whole String Instead Of Part

Jul 3, 2011

I'm not used to using "sed", but I need to use it to extract part of a string piped to it.

However, the "1" mentioned in the tutorials I read doesn't extract the token between the two brackets and returns the whole input string:

Code:
/tmp# echo "before [myfile.txt] after" | sed 's/[(.+)]/1/' before [myfile.txt] after

I expected simply "myfile.txt".

View 9 Replies View Related

Ubuntu :: GREP - Return Only Search String?

Jan 13, 2011

I have a mail.log file, of which I want to redirect only the search strings of the sender from=<example.sender@exampledomain.com> and the size size=4537 to a file.

In every case the sender string starts as from=<> and the size string starts as size=

What would be the grep command to redirect only the two search strings to a .txt file?

View 2 Replies View Related

Programming :: Check If A Part Of String Exist

Sep 27, 2010

I have a macro which I use with ROOT. In this macro I want to check if a part of string exist so I can ignore it inside a loop. So, inside a loop I want to have something like:

Code:
if (string == "pre_ti_data_bdt*" || string == "pre_ti_data_nn*")
continue;

but of course I cannot use * in this piece of code! How to do this trick in C++?

View 5 Replies View Related

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 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 :: Perl - Remove A Part Of String Unit1/U800/o

Apr 13, 2011

In a file,

I need to remove a part of string: /o

string:

or

the string can be

here I need to remove /d2

So, I need to remove everything after when I get last /

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

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

Programming :: BASH Read File Once Then Return To Top?

Aug 8, 2010

I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:

Code:

"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red

[code]....

single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:

KEYWORDS:

[ ]red
[ ]orange
[ ]yellow

[code]....

Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.

View 14 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

Ubuntu :: Bash Script - Removing Windows Return Characters

Sep 1, 2010

I've got a basic script, which parses data from a text file and performs actions based on that data. Here is my code:

Code:
dsrc="/home/russellm/sites/"
ddst="/home/russellm/othersites/"
while read SiteID
do
if [[ ! -d "$ddst${SiteID:0:1}" ]]
then
mkdir "$ddst${SiteID:0:1}"
fi
mv "$dsrc${SiteID:0:1}/${SiteID%*}" "$ddst${SiteID:0:1}/" | tr -d '
' done < sites.txt

The text file came from a windows system, and contains those return characters (). I 'could' just run the whole thing through tr and then run the script on the new data file, but I'm looking for a more elegant solution. As the code above shows, I'm trying to pipe the mv command though tr in order to remove the return character - but it's not working. I can't get this to work with sed either, so I know I'm doing something wrong. I also tried to remove it using ${SiteID%} - but that also failed. The characters don't show up in an echo, just when executing a command.

Output example (emphasis mine):
Code:
mv: cannot stat `/home/russellm/sites/B/B23467324
': No such file or directory
I'm tempted to just convert the file once and call it a day, but you know what it's like. To be honest, I'm starting to suspect that there are no return characters, and that I'm going about this wrong.

View 4 Replies View Related

Programming :: Bash - Automatically Build A Set Of Packages And Redirect Output Into Logs - Failed Make Should Return A Non-zero Value

Jun 27, 2011

I have a set of bash scripts that I'm running that automatically build a set of packages for me and redirect their output into logs. Basically, I have a bunch of lines that are something like this: ${CONFIGURE_DIR}/configure &> ${LOG_DIR}/log or cd ${CONFIGURE_DIR} && make &> ${LOG_DIR}/log, etc.

This is supposed to make the entire process silent. However, sometimes with some packages some output leaks to my console (either stdout or stderr). I'm thinking that maybe the configure scripts/make are executing commands within new shell instances that don't inherit my redirect, or something to that effect.

Another reason for thinking this is that in another part of my script I detect errors when running make by testing with "if [ $? -ne 0 ]", and if the redirect leaks to my console and also the leaked output indicates that the build failed ("make: Error" and so on), then my $? test fails (i.e., it thinks that $? == 0, whereas a failed make should return a non-zero value). It's as if my original script can't "see" the results from child commands executed from later scripts.

View 1 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







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