Programming :: C Truncating Strings
Dec 11, 2009
I wrote this small program that will truncate a string that's entered in by the user.An example of its usage:if the user enters in a string say "abcdefghijklmnopqrstuvwxyz" the program will only take the first 9 characters and truncate the rest so that the user can be prompted for a second string and not be worried about remaining characters left in the stream.Now this program works O.K. but I would like to find something in C that has this functionality build into it...Does anyone know of any function that will accomplish this.
View 1 Replies
ADVERTISEMENT
Jul 29, 2010
I want to search and replace strings in a file with strings in other files/i need to do it with big strings(string1 is big) and i want to use a txt file for this.But this code not working :
View 14 Replies
View Related
Sep 3, 2010
I am having a lot of problems trying to change one string by another using sed: the sentence is like this:
sed -i 's/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"/KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0666"/g' 50-udev.rules
it is just to fing the line with:
KERNEL=="tty[A-Z]*", NAME="%k", GROUP="uucp", MODE="0660"
[code]....
View 8 Replies
View Related
Aug 4, 2010
I am trying to replace a section of a file between the first instances of the strings {}, with the contents of another file. Example of the format of the file I'm trying to modify
Code:
Servername=something.com
hosts {
macaddress1
macaddress2
[code].....
Then captured all the "macaddress#"s to a variable and used sed to swap
sed "s/$CURRENTDATA/$NEWDATA/" filename
However I get 1 of 2 errors,
Using a small number of macs in "$NEWDATA"
sed: command garbled: s/ macaddresshere
Or when using a large number of macs in the $NEWDATA variable get
bash: /usr/bin/sed: Arg list too long.
how to replace a large block of txt in one file with another large block from another?
View 6 Replies
View Related
Feb 8, 2014
I use udhcp with some of my minimal installs. I've messed around with the code a bit when it wasn't working correctly - a few years ago. I will find time - I hope soonish - to figure out how to do a few other things with it.
For now though, I'm using this string to grab my ip after startup
Code: Select allsu -c 'ifconfig eth0&&ifdown -a&&ifup lo&&ifup eth0'&&/sbin/ifconfig eth0
I realize I could substitute ifup -a but I'm more interested in figuring out how to make ifup wait for the ip to become available if it is not available yet.
Never mind that one, just typing out the question answered it for me, when I find it in the scripting man ' ; : " & =
Or if there are any other suggestions for better construction of the string.
View 2 Replies
View Related
Jun 28, 2009
I have a PHP script written that is checking a string to see if it contains a link in it (i.e. a URL). I have the following if statement, that uses 3 possible regular expressions to determine if there is a link or not.
Code:
// check if we found a link
// links are denoted by strings that:
// - contain http://
// - contain www.*.*
[Code]....
I'm not convinced yet that writing a shell script to do this is the best course of action. If someone is capable of doing this with a Perl or a Python script that's fine too. If you want to make it super high performance and write it in assembly
View 1 Replies
View Related
Mar 24, 2010
what is the best command to use to parse strings?I have a variable $str and need to parse this string.Can you provide an example of the command used to get a substring of $str based on the index values of start and end
View 3 Replies
View Related
Feb 25, 2011
i have an sql table with 2 columns i run a script that randomly selects a word from the table in column 1.
the word is displayed on the screen and I guess what it means i concatenate the randomly selected word and the answer the script looks for a match in mysql if it finds a match it says "Good job!" if there is no match it will say "not correct". However when i get it right it says not correct even though when i echo the variables they look exactly the same. the script below:
#!/bin/bash
var=$(mysql translator -u root --password=*-N<<EOF
SELECT word FROM tagalog ORDER BY RAND() LIMIT 1
EOF
)
[Code]....
View 4 Replies
View Related
Jun 8, 2010
Using the regex.h functions, how do you:
1) get the matched strings?
2) get the strings that matched sub-expressions?
View 4 Replies
View Related
Jul 14, 2010
it is about 'strings' binary from binutils. I recently wanted to test what it does and how it works. The best I did was this:
Code:
#!/bin/sh
PROGRAM="
int main()
{
[code]....
Ok, from the output I don't get it.Can someone show me in a simple script, what is 'strings' good for ?
View 10 Replies
View Related
Sep 5, 2009
I have a set of numbers under some headers in a file:
FNUM,BNUM,C1N,C2N,C3N,C1S,C2S,C3S,
4535, 109, 5.5955, 5.6523, 5.8084, 311.419, 295.2540, 286.9984,
4536, 109, 5.7667, 5.7174, 5.6771, 291.782, 285.0646, 271.5945,
[code]...
View 2 Replies
View Related
Mar 7, 2011
I have a function that retrives text between title and links tags from an XML file, but what i want is to test if the title and link tags are between item tags. This is my code:
Code:
istringstream iss(content);
string line;
[code]...
View 1 Replies
View Related
Dec 15, 2010
if I'd a file like this
something
somethine123
begin something end
begin xyz end
somethingelse
and I want to find the strings only between begin and end, exluding begin and end; How can I grep that?
View 3 Replies
View Related
Nov 10, 2010
I am trying a search for a pattern in the file. I can have any character in the pattern. I am pretty sure I will have $, ", ', ^, ` etc., The Problem I am facing is if I use "" (double quotes) to enclose the pattern, it gives special meaning to $, ^ and " within the string. I have no control over the pattern input. I am getting it from some other file. On the other hand, If I use '' (single quotes) to enclose the pattern, it gives special meaning to the ' (apostrophe) within the string and terminates the pattern prematurely. How do I disable the special meaning these characters have? For example, in perl, I could enclose the pattern within Q and E. Is there an equivalent in grep pattern expression? I could find one in the man page of grep. Is there a solution to this problem?
View 5 Replies
View Related
Dec 7, 2009
I need to make a daemon which listens to port 81 for messages like [URL] So far I made a daemon which serves as a simple stream server: I set up a socket to listen to a non-reserved port (like 9999), but I don't know how to read the query strings.
Linux distro: Kubuntu 9.04
Language: C
View 5 Replies
View Related
May 6, 2011
I have an interpteter that supports string literals, and the way it works is that the lexer returns the entire string as a single token, with the quotes removed and escape sequences replaced with the literal characters they represent.
I already implemented single-quote strings, they don't interpret any characters specially except for the single quote. I partially implemented double-quoted strings, they already support all the same backslash escape sequences that C does. But I would also want to add variable substitution.
The way it would work is that "${expression}" would interpret the expression (which could just be a variable name) and replace itself with the result. But I have no idea how to do this.
In case it matters, I'm using a hand-written lexer and recursive-descent parser.
View 14 Replies
View Related
Jul 8, 2011
I have that script that checks the nfs mount points:
Code:
#!/bin/ksh
#set -xv
test="DO_NOT_DELETE"
rc=0
[Code]....
I am no expert in loops and it took me all day to write that. I couldn't really tell how to match the string in $df_file and $fs_share, so I did a little workaround with a count.
View 9 Replies
View Related
Jun 20, 2011
I was zsync-ing the latest Ubuntu 11.10 Alpha and thought I'd make a little GUI for it as a small project. The gui is set up, I just need to figure out how to run zsync with content from to variables, cto and cfrom. I tried the following code:
[Code]....
View 4 Replies
View Related
Apr 30, 2010
...and returning the index of the found element in its array.
I have:
for ((i=0; i < ${#array1[@]}; i++)); do
# Read each line of the file test
if [[ $(eval "sed -n '$(($i+1))'p test") == *${array2[0]}* ]]
stuff
I want to find the index of the found substring in array2 and only if it isn't found, move on to the next element of array2. I don't know the size of array2 so that [0] has just got to go.
View 14 Replies
View Related
Jun 12, 2013
I have a directory of orchestral music .ogg files from a family member. Each track is from a different artist and the CDDB entry adds a ":" character after the artist name in the track title.
Here is an example of what I am referring to:
Code: Select all13_-_Mozart:_Sonata_in_A_major_KV_331.ogg
I would like to parse file names in any given directory and search for the string Code: Select all: and replace it with Code: Select all_ According to this post on stackoverflow, I can use Perl to accomplish this task. I've tried Code: Select allperl -i.bak -pe 's/:/_/' but since I am still learning Perl I'm probably commiting a PEBKAC error.
How would I go about solving this issue with regular expressions using Perl?
View 3 Replies
View Related
Oct 14, 2013
I'm trying to search for several strings, which I have in a .txt file line by line, on another file.
So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.
So far, I've been able to do this, to search for individual strings:
Code: Select allimport re
shakes = open("output.csv", "r")
for line in shakes:
if re.match("STRING", line):
print line,
How can I change this to input the strings to be searched from another file?
So far I haven't been able to.
View 3 Replies
View Related
Jun 8, 2011
How can i use different starting and ending delimiters in awk to search for strings or numbers like:
:string"another_string
'number+another_number
now i want string and number as output from above lines. But if i use delimiter as : or ' it will print the entire line coz second delimiter is not same as first one.
View 4 Replies
View Related
Aug 23, 2010
I am trying to develop a method of reading files generated by other programs. I am trying to find the most versatile approach. I have been trying bash, and have been making good progress with sed, however I was wondering if there was a "standard" approach to this sort of thing. The main features I would like to implement concern reading finding strings based on various forms of context and storing them to variables and/or arrays. Here are the most general tasks:
a) Read the first word(or floating point) that comes after a given string (solved in another thread)
b) Read the nth line after a given string
c) Read all text between two given strings
d) Save the output of task a), task b) or task c) (above) into an array if the "given string(s)" is/are not unique.
e)Read text between two non-unique strings i.e. text between the nth occurrence of string1 and the mth occurrence of string2
As far as I can tell, those five scripts should be able to parse just about any text pattern. I am by no means fluent in these languages. But I could use a starting point. My main concern is speed. I intend to use these scripts in a program that reads and writes hundreds of input and output files--each with a different value of some parameter(s).
The files will most likely be no more than a few dozen lines, but I can think of some applications that could generate a few hundred lines. I have the input file generator down pretty well. Parsing the output is quite a bit trickier. And, of course, the option for parallelization will be very desirable for many practical applications.
View 14 Replies
View Related
Apr 26, 2011
I am looking for an easy way to convert any given maze.txt of any size to a internal array of strings(dynamically allocated). Important is that dimensions of the maze (row, col) shouldn't be written by the user instead they have to be somehow read from the file. This is not my homework assignment! It is a small part of a project that i never dealt with. I never read files to C string.... I made it for specific maze dimensions, but want it to work with any given .txt file.
View 9 Replies
View Related
Jul 16, 2010
Something very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search and replace strings. We also want to keep track of how many strings we've replaced.
I know that my command would look like this: <utility name> <filename> <stringToSearchFor> <stringToReplaceWith>
Code: #!/bin/bash
[code]....
View 2 Replies
View Related
Sep 29, 2010
I listen to some voice mail messages over the web. Firefox downloads the message as a ".wav" file, and then invokes amarok to play it.What I have been noticing, is that amarok seems to cut the message short.As an additional test, today after playing a message on amarok, I tried playing the same message with kaffeine. There was significantly more to the message when played on kaffeine. The particular message ended with the phone number I should call back (if I wanted to). None of that ending sentence showed in the amarok playback
View 9 Replies
View Related
Nov 24, 2009
How do you remove parts of strings using python? Such as, if I have something like:
Code:
erme1 sdifskenklsd
erme2 sdfjksliel
[code]....
View 3 Replies
View Related
Jan 15, 2010
I have a Linux (Kubuntu) system with a large (~20Gb) file which I would like to mess with. Specifically, I want to copy the entire contents of another large file (~12Gb) to the middle of this file, and keep the bits of the file which are not overwritten.This is what I want to happen, with the text between the pipes representing file contents:Before:
outfile: |abcdefghijklmnopqrstuvwxyz|
infile: |123456789|
After:
[code]....
View 1 Replies
View Related
Mar 22, 2010
dd if=/dev/zero of=/var/images/abc.img bs=1M count=0 seek=2097152 dd: truncating at 2199023255552 bytes in output file `/var/images/abc.img': File too large
The dd commad fails here saying its truncating if I try same command with less value for seek it works dd if=/dev/zero of=/var/images/abc.img bs=1M count=0 seek=2088960
0+0 records in
0+0 records out
0 bytes (0 B) copied, 2.1e-05 seconds, 0.0 kB/s
Whats the reason behind this and how can this be solved ? Note that there is 3.9T available on disk for the above commands to execute.
View 4 Replies
View Related
Mar 24, 2010
localhost is now fine and localhost/test.php too. However php embedded in html files refused to save in /var/www? what is wrong with my server not being able to read .php strings?
View 2 Replies
View Related