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


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

Fedora :: Replace A String By A String In Text File?

Apr 26, 2011

If I have a word in a text file and I need to replace it by another word (for example, i need to replace abc by fff) so what is the command I can type it?

I am using vi editor.

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

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

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

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

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

Server :: Bash Script To Test String Complexity

May 12, 2010

I'm looking for a script which is testing how complex an "added" string is, for example like the user is changing his password and check how complex it is, if it included letters (lower/upper case), numbers and other characters.Im doing this for password check, the user type's the password and must be 6 characters long, have upper case letters lets say and numbers and so on.If anyone knows where I could find some bash script which is doing this, it would be really cool.

View 2 Replies View Related

Programming :: Bash: String Verifier Doesn't Work

May 26, 2011

I'm currently learning bash programming and am trying to create a program to maintain a list of people. Here is the code so far:

Code:

#!/bin/bash
# Namelist
clear

[code]....

As you can see, I attempted to build in a protective measure to prevent duplicate entries using "if grep -Fxq "$FN $LN" /home/andrea/namelist.txt", FN and LN being first name and last name as you can see in the first read operation. However, this fails to actually work. Demonstrations:

[URL]

It saves the details to the file rather than displaying the error message, or in other words, it doesnt check the file properly.

View 4 Replies View Related

Programming :: Bash Thinks String Variable Is A Numeric One

Jul 7, 2011

Bash 3.1.7

Code:

Code:

Code:

I think read A1 A2 makes A1, A2 string variables. Then, when A2 gets the value 01, '01' should be a string. But for some reason bash takes it as numeric. I know there are no types in bash.

View 11 Replies View Related

Programming :: How To Truncate Last Two Characters If Its '_1'

Mar 17, 2010

In a file i have to grep for a particular word and cut 8 characters of that word and replace the last characters with space if it is _1.Eg: HP4350_1..i did grep|cut -c 2-9|but didn't know how to truncate the last two characters if its '_1'.i used tr '[_1] '[ ]'.but it replaced all the characters where there is a 'underscore' and 1 instead of'_1' together.

View 5 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 :: Nontrivial String Replacement With Bash On-board Means?

Jan 9, 2011

My simple bash-script replaces --> by the HTML-entity for the right arrow. To be precise, it replaces --*> by → Until now, I used sed, for example:

Code: $ flight='AMS --> JFK'
$ echo "$flight" | sed -e 's/ --*> / → /g'

AMS → JFK With sed, -* matches zero or more dashes, because for sed the * is the Kleene Star matching zero or more instances of the previous element. So with sed, --*> matches exactly what I want:

Code:

->
-->
--->
---->

Because sed seems oversized for that task, I played around to accomplish the same with on-board means of bash without using sed. On first thought, this line looks like doing the same but it isn't:

Code: $ flight='AMS --> JFK'
$ echo "${flight// --*> / → }"

AMS → JFK As I recently learnt in this forum, this * isn't the Kleene Star. It is a multi-character wildcard matching any zero or more consecutive characters. So here, --*> matches:

Code:

->
-->
--->
---->
-<>
->>

-abc> And if you continue your flight to SEA, then the result is totally wrong because the * matches greedily:

Code: $ flight='AMS --> JFK --> SEA' $ echo "${flight// --*> / → }" AMS → SEA

The sed line above would produce the correct result and would match the dashes correctly.

View 3 Replies View Related

Programming :: Find String In Text File (bash Script)

Apr 17, 2011

write such script (bash script). I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.

For example. File: PHP Code: PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22) 

[Code].....

View 1 Replies View Related

Programming :: Bash: Functional Difference Between Process Substitution And Here String With $( )

Mar 14, 2010

Further to solved LQ thread Bash: how to populate a list of arbitrarily named files?, what is the functional difference between feeding a loop with process substitution and feeding it with a here string with embedded command substitution? ABSG pages: process substitution, here string and command substitution. This works

Code:

while IFS= read -r -d '' file
do
files+=("$file")
done < <(find $dir -type f -print0)

[code]....

View 2 Replies View Related

Programming :: Bash Regexp String Compare Stopped Working?

Oct 20, 2010

Have a bash script which contains a line like this:

if [[ ${array[${last}]} =~ "screenpc.PRODUCTION.*" ]]

which WORKED as expected in bash 4.0.33 and now fails in 4.1.2

Instrumented the script to print the value of the left-hand side and it is exactly what is expected.

As noted above, this has been working fine until we installed Fedora 13 (kernel 2.6.33), and now it fails.

Tried setting shell 'extglob' to On with same results.

Did something change? Are there other shell/bash options that need to be set?this has the whole installation stopped!

View 10 Replies View Related

Programming :: Find A Substring/member In A String/array Using Bash?

Oct 13, 2010

This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory

Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these

[code]...

View 4 Replies View Related

Ubuntu :: Bash Script To Delete/replace A Specific String Of Text?

Jun 17, 2010

What i want to do is pretty simple.I want to uncomment every line that begins with "deb" (except for deb cdrom) in /etc/apt/sources.list.I know how to do this through system > administration > software sources.I know I can gksu gedit /etc/apt/sources.list.I'd rather not do it that way.I'd rather have a script do it. It's less work, less typing, less clicking, and would work the same on every ubuntu version.

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







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