Programming :: The 'a' String Doesn't Have Any Spaces In It?

Nov 27, 2010

I have a file of the type:

a = b

where a is any string and b is an integer The 'a' string doesn't have any spaces in it.

Everything was running fine till I was searching for 'a' and finding value 'b' by expression

Code:
string="$a"
egrep -i -m1 "^[[:space:]]$string[[:space:]]*=" | awk -F'=' 'gsub(/^[[:space:]]+/,"",$2)gsub(/[[:space:]]+$/,"",$2){print $2}'

I recently ran into a situation where in the string 'a' had symbols like $, & in it. Though I haven't checked it for & but $ is definitely breaking my code

Any way to egrep for string with $ ??

One way I though was to replace every occurence of $ with $ in my search expression but that would involve an extra processing each time

View 10 Replies


ADVERTISEMENT

Programming :: C++ Won't Detect Spaces In A String?

Oct 8, 2010

I have been trying to code a program in C++ that must check for the correct syntax in order to operate. It must find ", " within the string, but I don't know why the compiler won't recognizes spaces.

Code:
#include <iostream>
#include <stdio.h>
#include <string>

[Code]....

So the user must input "<name>, <interest>" with the ", " (comma and space) but even if you respect the syntax the compiler will skip to the else condition. I don't know why, but if I put any other condition like ",s" it will work, but not with spaces.

View 7 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 :: Selectively Remove Blank Spaces From String?

Oct 7, 2009

need all spaces between two letters or a letter and a number exchanged for an underscore, but all spaces between a letter and other characters need to remain. One example for clarity:

Input:

force -- lamin 90 [label]
active A -- generation [label]

needed Output:

force -- lamin_90 [label]
active_A -- generation [label]

I tried solving this with sed but obviously s/ /_/g does not work, nor does any s/[a-zA-z0-9] [a-zA-z0-9]/[a-zA-z0-9]_[a-zA-z0-9]/g , because you just can't do this...

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

General :: Search A String Having Spaces / Slashes / Colons In Vi Editor

Feb 2, 2010

I need to seach a string containing

the substring of 'New Request object:'

and

the substring of '/0x2ab46b1f90' in vi editor,

how do I accomplish that?

View 7 Replies View Related

Programming :: Pthread - Take String From The Command Line And Creates A Thread To Print The String

May 3, 2011

I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.

[Code]....

One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?

Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.

View 6 Replies View Related

Programming :: Using Sed Replace Line Containing Particular String By A Single String?

Oct 16, 2010

I have a set of lines as ahown below:

Leon went to school
Leon came back from school..
Leon had dinner...

I have to replace the line containing "dinner" by a single string LUNCH...

View 2 Replies View Related

Programming :: Creates String Suffixes Out Of A Reference String?

Feb 25, 2011

I need to creates string suffixes out of a Reference string. for eg. suffixes of abcdefg will be

1)bcdefg
2)cdefg
3)defg
and so on...

create an array of pointers to point to the first few characters and then use that pointer to print the rest of the string.But when i print using the pointer i get GARBAGE values! shudn't std::cout<<ptr[w] print the string following the char it is pointing to? why do i get garbage values?

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

Programming :: Convert String To Integer Back To String C++ ?

Mar 13, 2010

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:

View 1 Replies View Related

Programming :: Assigning Custom String To Std::string In C++?

Oct 12, 2009

I've been given a custom-made string class which handles string, wstring and bstr. It has a number of methods and assignment operators to convert to and from different types. The app I work on compiles happily in VS6 and VS2008, but when trying to compile in Redhat (version 4.1.1 in Redhat 5.0)

[code]....

View 4 Replies View Related

Programming :: How To Check If All Letters Of One String Are In Another String?

Nov 11, 2010

I have the following two type of strings1: A/D2: A/C/DI am trying to write a subroutine to check whether all of the letters in string 1 appears in string 2. If yes, return true. If not, return false. In the above example, all the letters (A and D) in string 1 are also present in string 2, so I return true.

View 4 Replies View Related

Server :: Using Locate With Rm - Doesn't Work When Pathnames Occasionally Contain Spaces

Mar 2, 2011

does anyone know how can I use locate with rm? rm `locate "some file"` does not work when my pathnames occasionally contain:

-spaces and other characters (like + or possibly others that need escaping)
-greek characters

how can I grab line-by-line the output from locate and wrap quotes"" around the paths?

View 5 Replies View Related

General :: Shell - Rename A File From Something Without Spaces To Something Containing Spaces?

Jan 26, 2010

Is it possible, in Linux, to rename a file from something without spaces to something containing spaces? I know I can create directories and files with spaces by doing:

mkdir "new dir" and:

touch "new file.txt"

I want to rename files from:

imgp0882.jpg to something like:

20091231 1243 some topic.jpg

And how would it look in a shell script that uses parameters like:

for i in *.jpg do
rename "$i" "$somepath/$mydate $mytime $mytopic$extension"
?

I'm new to Linux (using PCLinuxOS 2009.2), coming from Windows, and I've written myself a little shell script to download files from my camera and then automatically rename them according to a date-and-topic pattern. As you can guess by now, I'm stuck on the bit about renaming. If you want to see my script, here's a copy. I'm not using jhead for this renaming because that only works with JPEG files but I want a single solution for any media format including videos.

View 2 Replies View Related

Programming :: Missing Separator Mean Tab Instead Of Spaces?

Jul 9, 2010

I am unable to write a simple Makefile. Though I know the concept am facing this error:
Makefile:2: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.
Should I give a tab or spaces not able to continue.

View 5 Replies View Related

Programming :: Python - How To Avoid Spaces

Oct 1, 2010

In the code below:

Code:

The output is:

Code:

Looks like the "," operator in the print inside the loop is adding a space for its own.

I want to print the sequence WITHOUT spaces. Something like this:

Code:

But I couldn't figure out how to do this.....

How to print a sequence, inside a loop, without that space ?

View 14 Replies View Related

Programming :: Pad End Of Each Line With Spaces To = 80 Chars?

Apr 14, 2011

I've searched the forums and the google looking for a means to do this and haven't found anything I can use. I have a large file that looks like this:

Code:

18000034161828M850
18000034172676M850
98 093095

[code]...

I need to add spaces at the end of each line to ensure that every line has 80 chars before the carriage return. I was thinking something like this, but it doesn't do the right thing:

Code:

cat filename | sed -e 's/$/(bunch of spaces)/' | cut -c1-80 > filename2

I'm on fedora, so I can use awk, sed, bash, ksh, etc.

View 14 Replies View Related

Programming :: Spaces Versus Tabs

Feb 24, 2010

Which do you prefer and why? Also, I remember someone telling me once that while using space indentation use either 4 spaces or 2 spaces. Don't use 3 spaces. Anyone know why they would say not to use 3 spaces?

View 14 Replies View Related

Programming :: Variables With Spaces In Remote Ssh?

Nov 22, 2010

I'm writing something which takes user input (which may or may not contain spaces...) and then runs a command on a remote system via ssh. However the remote command does not work. I can't print the exact code so I'll just provide an equivelenat problem. This needs to work with filenames which do and do not contain spaces.

Code:
FILES=`ls`
echo "Specify a file"
echo "$FILES"
echo -n "File name: "
read $FILES
ssh root@127.0.0.1 "ls $FILES"

View 5 Replies View Related

Programming :: Bash File Names With Spaces?

Jul 24, 2010

I have a laptop that I am in through SSH. The laptop does not have an Xwindow system so I am using the program fbi to open an image on my laptop screen from my SSH connection:

fbi -T 8 picture.jpg #this opens the image on the laptops tty8 terminal

I've found that making a for loop does not work with files that contain a space in the name. Something to due with a bug that they call a "feature" that stops the first variable at the first whitespace.

Using a "while" loop is not exactly what i require either seeing as I want to be able to view each image in the directory on screen and tag it accordingly, before it jumps off to the next image, and I'm not sure how to add a pause to a while loop.

How do I make a Bash script and loop Variables handle files like "files that contain spaces.jpg"

View 5 Replies View Related

Programming :: Grep Ignoring Spaces Or Tabs?

Jun 29, 2010

I writing a script to go through multiple reports. I want to grep daemon.debug @10.10.10.10 on all reports to make sure it is pointing to the right IP address. the problems is the space between debug and @10 are different on all the reports, some have one space some have two and some have tabs how do I ignore the tabs or spaces and grep daemon.debug @10.10.10.10

daemon.debug /var/log/ftp rotate size 20m files 4 compress
daemon.debug @10.10.10.10
authpriv.* /var/log/secure rotate size 20m files 4 compress
authpriv.* @10.10.10.10

View 6 Replies View Related

Programming :: Bash Script And Filename Spaces ?

Jan 15, 2010

I have over 50 files names with spaces in them.

I'm trying to use a for loop as such:

However, when I print the $filename in the script, the script prints out parts of the filename because of the spaces in the file name.

For example, say the file name was Star Quest.php

When the script executes one $filename would be Star and another Quest.php.

How could I account for this? Something like $'filename'

View 13 Replies View Related

Programming :: Using Sed To Remove Preceding And Trailing Spaces In CSV?

Sep 16, 2010

the preceding and trailing spaces around the commas in my CSV without destroying my address field. I'm new to regex and sed so this is probably easy but I just can't do it without destroying the Address section. I'm using vanilla Linux and sed 4.1.3I'm willing to use any regex or even awk if needed.

Example:
I need this
randall , dean, 11111 , 1309 Hillside Ave., Warsaw, VA , 23591

[code]....

View 11 Replies View Related

Programming :: Php Scripts Cant Locate Filenames With Spaces?

Apr 13, 2011

I have a fresh dedicated server that im currently configuring and needed a little help if I may ask.The problem is that i'm having a file naming issue. for example from the web I can access any file that does not have spaces of any type. ex/music/musicfile.mp3this works fine and my php script can locate itBut the problem is when I try to access a file that has spaces.ex/music/The Eagles - Hotel California.mp3my php script can't seem to locate any files like this with spaces but doesn't have a problem locating the files with no spaces.

I also took a look at the directory within shell. I did notice that files that have spaces are showing up in this formatt in shell.#/home/~username/public_html/music/The Eagles - Hotel California.mp3In shell , i'm assuming that unix/linux maybe adds a backslash before spaces. But when I FTP to this same directoy, the filename look normal and at windows standard. how could I correctly access these types of files within my php scrits? or would I need to have all uploaded files renamed so that spaces are replaced with underscores maybe?

View 4 Replies View Related

Programming :: Sed Insert Line With Leading Spaces?

Mar 3, 2011

I'm trying to insert a line using sed that has leading spaces before the text. Sed seems to be just dropping the spaces and only inserting the text. Any ideas what I'm missing?

Code:

NAM=rb134
sed -i.bak -e "$i
host ${NAM} {" /etc/crap

Instead of inserting a line with 8 leading spaces inserts it with "host" at the beginning of the line. I tried

Code:

NAM=rb134
sed -i.bak -e "$i
^ host ${NAM} {" /etc/crap

but it put the "^" at the begging of the line.

View 6 Replies View Related

Programming :: Reading And Writing White Spaces To A File?

Dec 2, 2010

I am trying to read a file character wise and trying to write the same character to another file. In this process, I unable to read and write white spaces successfully to the new file. The script reads the white spaces but while writing the white space is lost. The section of the code, is given below. Please advice how can i read and retain the white space while writing to a new file.

Code:

if [ -s f_test.txt ] && [ -f f_test.txt ]; then
echo "File Exists !!"
while read -n1 char; do

[code]....

View 2 Replies View Related

Programming :: Replace Spaces With Underscores In File Names?

Jan 11, 2011

I often get files with many spaces as part of their names. I would like to automatically replace these spaces with underscores, but otherwise not change the file name. Is there a way to do this task with just the bash shell?

View 4 Replies View Related

Programming :: BASH Script: Spaces Are Getting Converted To TAB Character?

Dec 23, 2010

I have a BASH shell script with embedded SQL script. The SQL script fetches the data from oracle server and the data contains more than 8 spaces in the value (eg, 28051630 A) and the data is written to flat file using the below syntax:

$ORACLE_HOME/bin/sqlplus -s ${CONNECT_STRING} >${out_file} <<!!
.. sql query..
!!

The problem is that whenever the data is written to ${out_file} spaces are getting converted to TAB character

eg, 10 spaces (in Oracle) converted to 1 TAB and 2 spaces 7 spaces (in Oracle) converted to 1 TAB and 1 space Also, from above example you can see the width of TAB char is not constant (8 in first example and 6 in second example) Is there any way that I can stop shell script to convert spaces into TAB character as I want the data as it is from Oracle DB (i.e. only spaces not TABs)

View 3 Replies View Related

Programming :: Handle Files With Spaces In Their Names In Bash?

Apr 1, 2011

*I'm using Ubuntu 10.10

My issue is I can't handle the files with spaces in their name, I've donde the below script to print each file found inside folder and subbfolders with "find".

I would like to "ls" to each file found with its complete path and with its basename too.

Code:
files=$(find . -type f)
for each in "$files"
do
ls -l "$each" # 1rst option I've tried to list with full path
ls -l "$(/bin/echo "$each")" # 2nd option I've tried to list with full path
ls -l "$(/bin/echo $(basename "$each"))" # 1nd option I've tried to list with it basename

[Code].....

How can I list "ls -l" in both cases (with full path and with basename) when there are files with spaces in their name?

View 6 Replies View Related







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