General :: Awk - Convert Variable To String?
Nov 15, 2010How do i convert variable to string?
For example:
So how do i make the code with variable work?
How do i convert variable to string?
For example:
So how do i make the code with variable work?
Do I have the convert the int to a string using stringstream then convert the string to a char? or is there a more direct way?Also is there a way to tell the length of a int?
View 5 Replies View Relatedmy 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#+}
I'm facing problems in developing the script as there are errors that sometimes i dun have any idea on how to solve it.What i'm doing now is not homework, but i had been assigned to develop some system in linux.
My problem currently is on sub-string matter, where i need to read the line from file/directory and based on the line retrieved,i need to seperate the information in the line and assign as variable..
Below are my script:
Thus, the output something like this: file_name successfully ran on Mon Jul 12 23:15:00 SST 2009.
Now, what i need to do is to extract certain information from that line which is the name, date, time and the status
The desired output is:
So,my next step is to identify the sub-string and assigned as variable first in order to parse the info and output it.
Thus,my script is:
But i received error message which is:
Code:
The error is:
Code:
What I want to do is take input of ip4 as a string, convert it to an integer to add 1 to it, then reconvert it back to a string. Its not working.
My full code is:
Code:
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?
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 RelatedI 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 RelatedI want to convert strings like 002, 049, 050, 100 to numbers: 2, 49, 50, 100.
I tried to use:
Code:
`printf "%5d" $i`
, but it doesnt work , it convert:
002=>2
014=>12
049=>0
(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.
I need to search a text file for a string of numbers which are different lengths, and always are between number=" and " like:
number="1234567890"
number="22390"
I need to grab those numbers and pipe each one to a line in a file. I've already tried something with awk and that didn't seem to work.
How to change string variable in awk? for example, I parse with awk script text file named some_name_with_extension.txt
I want to print only some_name in my script
Code:
....
varCompName = FILENAME
print varCompName
How to put not all symbols from FILENAME to variable?
This make my day
In windows I used some of next
Code:
%my_var:~0,-2%
would extract all but the last 2 characters of the my_var variable.
How to change string variable in awk? for example, I parse with awk script text file named some_name_with_extension.txt
I want to print only some_name in my script
Code:
....
varCompName = FILENAME
print varCompName
How to put not all symbols from FILENAME to variable?
[Code].....
I am bad with bash programming and I need some help how I can make variable names out of a string.I will need some help start doing that. And I think the first would be to get part of the filenames strings into variables.
View 7 Replies View RelatedI 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:
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.
I'm trying to pass a path as a string to an array, but its evaluating it as a command instead. I want to take the literal string "/mnt/accounts/user/temp/*.jpg" and assign it to an array{1}, but when i echo the array variable, it displays it as
pic1.jpg
pic2.jpg
pic3.jpg
[code]....
I just want it to be the actual text "/mnt/accounts/user/temp/*.jpg" which i will be combining with other text to create a longer path elsewhere in the code.
The script produces 2 empty lines and I don't know why.
View 1 Replies View RelatedIam trying to check a value less than or equals 0.The value iam getting is after doing grep a file . but its throwing error .
Code:
When i execute this it throws
Code:
I want to append a variable string to the end of a specific line. not like append the same string to each line. like in my file i have 4 columns, i want to add a string in 5th column in some fixed row.
View 4 Replies View RelatedBash 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.
how do you include a string variable as part of a regex in Perl?
View 5 Replies View RelatedI've searched around and can't find out how to convert a string ( like "12345" ) into an int array ( x[ 5 ] = { 1, 2, 3, 4, 5 } ; ).
View 4 Replies View Relatedconvert string to long ?
View 4 Replies View RelatedSomeone know how i can convert from hex string to double in c/c++?? Example 40668472B020C49C is 180.139
reference page: http://babbage.cs.qc.edu/IEEE-754/64bit.html
i have problem in java. how to convert string array to character. e.g string a[]={"ab","abc","abd","ag"}; what will be the character array ?
View 3 Replies View RelatedI'm trying to convert an 8 digit string into a long. The code compiles, but I'm getting only 1 digit placed into the long.
[Code]....
Like the binary form of the integer '2' is '10',
How should I find out the binary form of a string say "abcd" ?
Code:
FILE_SIZE=`find /var/logs/ -type f -mtime +5 | wc -c`
im trying to convert FILE_SIZE into megabytes
[code]....
I used xbindkeys and xvkbd to map my extra mouse buttons to page up and page down. With kde 4.4 it worked, but since I upgraded to kde 4.5 beta, I get the following error when xbindkeys starts:
Code:
*** Warning ***verify that there is not another program running which captures one of the keys captured by xbindkeys. It seems that there is a conflict, and xbindkeys can't grab all the keys defined in its configuration file. And for button press I get
Code:
Warning: Cannot convert string "-*-lucidatypewriter-bold-r-*-*-12-*-*-*-*-*-iso8859-1" to type FontStruct
Warning: Cannot convert string "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1" to type FontStruct
[code]....