Programming :: Remove The Last Character From Variable

Jun 22, 2010

i have the following:

Quote:

echo %host%|sed "$s/.$//"

this would remove the Last character of the value assigned to the %host%. for example if my value is: abcd i get abc. but i am not able to assign the output. for example when i do

Quote:

set k=`echo %host%|sed "$s/.$//"`

after doing echo %k i get no output at the command prompt...!! whereas when i just type:

Quote:

echo abcd|sed "$s/.$//"

at the command prompt i get abc. maybe some other ways to Remove the Last character...?

View 13 Replies


ADVERTISEMENT

General :: Remove A Certain Character From A Variable?

Jun 15, 2010

I want to remove single quote from a variable. eg: Suppose I have a variable VAR='TEST' (including single quotes) How can I remove single quotes and make it TEST.

View 5 Replies View Related

Programming :: Check If A Variable Holding A Character Is A Hyphen?

Mar 4, 2010

I am having trouble with the code below, I'm trying to check if a variable holding a character is a hyphen.

Code:

#!/bin/bash
$char="-"
if (( "$char" == "-" )); then

[code]....

View 3 Replies View Related

Programming :: How To Remove The Last Character

Jun 27, 2010

I have a string like this "/home/test/filename.txt" and i want to delete all character after the last "/". how to do that using sed or awk.

View 5 Replies View Related

Programming :: Remove First And Last Character?

Feb 24, 2010

which is the simplest way to have first and last character cropped out from a string? Something simpler than

Code:

echo $STRING | cut -b 2- | rev | cut -b 2- | rev

View 6 Replies View Related

Programming :: String Editing: Remove Lines Consisting Of A Single Character?

Jul 16, 2010

I have a large text file that's formatted sort of like this:

Code:
foo bar
blah

[code]...

View 2 Replies View Related

Programming :: Remove Characters From Within Variable

Feb 20, 2011

I am doing a mysql query with a bash shell script like:
mysql translator -u root --password=******** -e "SELECT word FROM tagalog ORDER BY RAND() LIMIT 1" | while read line; do
echo $line

So when I echo the value of $line I get:
word
magandang umaga
"word" is the name of the row in the table and maganda umaga is a randomly selected choice from the row. Is there a way i can remove the name of the row from the variable $line. With a result that will allow me to echo $line and output only the randomly selected entry in from the row e.g. magandang umaga

View 13 Replies View Related

Programming :: Shell To Remove Line Matched With Variable?

Jul 25, 2011

I'm using sed to remove certain line in a text file based on a match with 2 variables from input. Here is how it looks like in file

Philip S:Odds:45:343
Mike Junior:Odds:3:56

I prompt for 2 inputs in variable form which is compared to the first 2 fields of the above text (: seperated). So say i enter Philip S and Odds then it should delete the entire first line.

View 4 Replies View Related

Programming :: Remove Line Containing Certain Variable - Bash - Permission Denied?

Jul 20, 2011

I am writing a bash script to run everyday and output results to a file. When the same results are produced i want to overwrite the line from the previous day. (Or remove and add). So if the script finds a variable in a line. i want it to output the results to that line . sed -i did not work for me; sed: couldn't open temporary file ./sedTvOCEg: Permission denied

View 10 Replies View Related

Programming :: Script To Remove Lines In A File With More Than "x" Instances Of Any Character ?

Oct 4, 2010

I'm looking for a script (bash, python, perl etc) or even a one liner (sed, awk etc) that can take a set of files and remove any line that has more than "x" instances of any character (case sensitive). I have been doing a lot of searching and can only come up with examples of how to remove blank lines, lines that start with a certain character or lines that contain a certain string. This will be used on a system running a Kubuntu derivative.

As a very poor and basic example, I would like to take files that contain lines like:

Code:

And end up with the files only containing the lines:

Code:

If I tell the script that 2 is the maximun number of times any character can appear in any line.

I know this must be possible, but for the life of me I cannot find even an example that will lead me in the right direction or better yet a piece of code I can use.

View 15 Replies View Related

General :: Special Character In String Variable And Grep

Apr 11, 2011

I want to match some filename in some text, but the filenames I have no control of, so "[" can "]" can appear in the filenames.so do I always have to use sed to addslashes to these variables before I have to grep them? and what other characters have I missed other than "[", "]", "."?

View 4 Replies View Related

General :: Use The Man / Info / Apropos Pages - Character Instructed The Shell To Interpret A Special Character As An Ordinary Character?

Mar 27, 2010

1.What character instructd the shell to interpret a special character as an ordinary character?

2.What directory contains some of the utilities available on the system in the form of binary files?

3. What command is used to search the location of a utility?

4. What command is used to instruct the editor to write the file and quit the editor?

5. What key quits the more utility and displays the shell prompt?

6. What command starts a child shell as the super user, taking on root's identity and environment?

7. Which wildcard characters can be used for searching all the files in the system that start with "A"?

8. The user name or login name of the super user is????

[Code]....

View 10 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

Programming :: Make A New Variable With The String From The Old Variable Btut Without Any Plus Sign?

Apr 7, 2010

my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.

i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't

foo=+12.40
bar=${foo#+}

View 4 Replies View Related

Programming :: Search Within A Variable And Assign The Results To A New Variable?

Apr 25, 2011

how I can search within a variable and assign the results to a new variable. I'll use the following as an example -

cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`

with the echo command I get the following output assigned to list -

A
C
C

What I'd like to get for output is -

Audi
Cadillac
Chevy

how I could do this regardless of upper/lower case letters?

View 5 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

OpenSUSE :: Remove The Tab-like Character In Terminal?

Dec 8, 2010

In my terminal , there's always a tab-like(a long space) between the "pswz-zhangy@linux-buym:~>" and the cursor, how can i get rid of if?

View 5 Replies View Related

General :: Remove Abnormal Character DEL From A File Name?

Jul 22, 2011

I have got certain files which somehow contain abnormal character "Del" "0x7f" or 177 which represents Del. And this is causing SVN to reject these files and abruptly end the process. I need to remove those characters from the file names but am not able to. find or grep do not search the files. This is how the file looks like with ls or find code...

View 3 Replies View Related

Programming :: Assignment To A Variable Variable?

Mar 17, 2011

This loop is part of a bash script which takes multiple arguments.

Code:
for ((i=1;i<=$number;++i)) ; do
offset=$(($i+5))

[code]...

View 3 Replies View Related

General :: Shortcut To Remove First Character Of Multiple Lines In Gedit

Jan 23, 2010

I want to be able to remove the first character of a line when I highlight multiple lines in gedit. Example:

%Example is
%Commented Code
%Uncomment using this shortcut

I would then highlight/select these lines, and remove the first character to make it look like this:

Example is
Commented Code
Uncomment using this shortcut

I'm pretty sure there is an actual shortcut for this. If there is another text editor on Linux that it would work in, it would be nice to know how to do it in that editor as well.

View 2 Replies View Related

Red Hat / Fedora :: Change File Names To Remove Invalid Character

Apr 1, 2009

I am trying to copy a large number of files from a Linux server to a Windows file share. Unfortunately, all of the files and folders I have to copy have 10 numbers followed by 2 colons "::" in the name (example: 1234567890::WordDoc.doc) which of course is invalid in windows naming conventions. So now I'm trying to come up with a way to change the file and folder names on the fly to replace the colons with a dash "-" or space " ". I'm even willing delete the frist 12 characters in necessary. I have tried cp, mv, tr, and several -bash scripts but get no positive results.

View 4 Replies View Related

General :: Remove Lines With Variable Value?

Jul 20, 2011

I have model output data in ascii format. It contains thousands of lines. The output file contains multiple text lines with variable values. here I copy-paste some of it's contents.

Code:

73438 170 23:53:20 3.481328E-03 1.824611E+04 1.824612E+04 1.333962E+16
73439 170 23:56:40 3.481210E-03 1.824611E+04 1.824612E+04 1.333962E+16
73440 171 00:00:00 3.481093E-03 1.824611E+04 1.824612E+04 1.333962E+16

[code]....

i want to remove the lines starting by WRT and DEF.

View 7 Replies View Related

Programming :: Character Arrays In C?

Nov 3, 2010

I was reading Kernighan Ritchie book chapter 4 which deals with character pointers.I am not able to understand following different type of declarations

Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time";

[code]...

View 1 Replies View Related

Programming :: Get Value In Character String?

Oct 23, 2010

i am compiling the following program in linux. it's in c language. after the compilation with gcc when i run the executable file. it asks for input. but when i enter a name. i prints "Segmentation fault" and then terminate the program. can you please help me.

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>

[code]....

View 1 Replies View Related

Programming :: Sed Substitute Everything Until Character?

Mar 30, 2010

I have the following file:

Code:

1 line
...
49 test test=AA:AA:AA:AA:AA=0

I need to substitute on the line number 49, all text until =. I have used the following, but with no actual result.

sed -re '49s/^.+=//' file
and
sed -e '49s/.*[=]//' file

View 5 Replies View Related

Programming :: Pass Variable In Mysql Qyery In C Programming?

Dec 4, 2010

i want to pass variable in mysql qyery in c programming

View 1 Replies View Related

Programming :: Check Whether The First Character Is TAB Or Space?

May 11, 2011

I have a file with one line. I want to check whether the first character is TAB or space, how can i do this.? using "cut" wont as it "bypasses the tab and space characters"

View 3 Replies View Related

Programming :: Awk Character Position Matching?

Apr 22, 2011

I am trying to check if the 9th character in a file on each line is a v and if so, then print the first word. I've tried a number of variations and am stuck !If it's possible to also check if character position 1 begins with a s in the same awk, that would make it cleaner instead of using egrep.

egrep '^s' file | nawk '{virtual=substr($0,9,1); if ($virtual=="v") {printf "%s", $1}}'
nawk: illegal field $(e)
input record number 1
source line number 1

View 13 Replies View Related

Programming :: Best Way To Flush A Character Array

Aug 2, 2010

I believe I have unwanted ' characters left in a 9 element character array that are causing subsequent operations with it to fail. I see wildly differing views on the web on the proper way to flush 'em. It's clearly not as simple as it would appear at first sight. What's currently the best (or else "least deprecated") method?

View 5 Replies View Related

Programming :: Counting To A Specific Character?

Feb 12, 2010

I am loading variables for cXtXdXsX disk names into a script, and at present I have only accounted for there being 3 characters from c to t. I need to change it to a variable recognition so that it can count any number of charcters such as c1t , c10t , or c100t.

I can then take that information and use it with the following string to strip off the lead characters so as to make the 3 in $substr either a variable or redirect to multiple occurrences of raw based on the count returned.

sub raw {
$substr = substr ($_, 3);
$raw1 = substr ($substr, 0, -4);
$raw = lc($raw1);
}

how to count from the c to the t inclusive so I get 3, 4, 5, etc ...

View 9 Replies View Related







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