Programming :: Read A File And Parse A String In C++
Jul 26, 2010I need to read a file and parse a string. I know in Perl there is the split command. Is there something similar to that in C++?
View 6 RepliesI need to read a file and parse a string. I know in Perl there is the split command. Is there something similar to that in C++?
View 6 RepliesI am trying to make a perl script which reads data from a file and parse it. The data in the file has the following syntax
Code:
Device Physical Name : Not Visible
Device Symmetrix Name : 1234
Device Serial ID : N/A
Attached BCV Device : N/A
Device Capacity
[Code]...
Each unique record starts with "Device Physical Name". So, I have a set of records within "Device Physical Name". I want to read this set of records starting from "Device Physical Name" and ends up till next "Device Physical Name". Offcourse FS is ":", and I just want to print/or later put info in a csv file.
How to let awk consider a string by double quota as one field? for example:
echo "first "second is a string"" | awk '{ print $2 }'
I want to print out "second is a string".
I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files.Say a file abc.log exist on 2 servers.I want to search for string "test" on both files and calculate the total count of search string's existence.For example if file abc.log on server 1 has string "test" 2 times
and file abc.log on server 2 has string "test" 4 times.then the output will beStringName : Countexampletest : 6 timesNote : I have created the password less connectivity using ssh-keygen.
here is the problem code using strptime() function.
==================
#include <stdio.h>
#include <string.h>
#include <time.h>
[code]....
Why are the Month and Year so messed up? I am using strptime() according to the man page.
I am working on the script to parsing the specific message like "aaaa" in multiple log files like N1-***,N2-***,N3-***..The script is to find the list of lof files which contains the message "aaaa" and export the list into excel filE.
View 4 Replies View RelatedI have the following code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
system("ps -ef | grep myprocessname");
return 0; }
When I run this program it outputs the following list of running processes:
Code:
root 10279 10275 0 13:02 ? 00:00:00 myprocessname myvar1=value1 myvar2=value2
root 10341 10337 1 13:02 ? 00:00:00 myprocessname myvar1=value1 myvar2=value2
What I want to really do is instead of writing the output to screen I want to read the output and parse the various values value1, value2 etc. What is the best way to do this?
I want to read the line in the text file and get the string in the file and paste it in the directory column
for example i have a line like /ftp/prod/SWC1407.DOC
from this 1407 should be parsed and appended at the end of the move command
mv /ftp/prod/SWC1407.DOC /nfp/1407
I want to read a string into shared memory using shmget and shmat. I'm using something like:
Code:
char *bookmark_strings, *s;
Book_Key = ftok(SHM_LOC,SHM_KEY);
shared_bookmarks = shmget(Book_Key, MAX_BOOKMARKS * sizeof(bookmarks), (0644 | IPC_CREAT));
bookmark_strings = shmat(shared_bookmarks, NULL, 0);
s = bookmark_strings;
*s = "hello";
I know that since it's a string I should be using something other then just char, but with something different shmat fails to be assigned.
in gcc how to read a blank line ie a string of length 0.my code:
Code:
#include<stdio.h>
#include<string.h>
[code]...
I have to parse a file containing billions of records and populate them in the Data structure. I have used a lot of C++ class and creating objects of the class I am storing the information retrieved by parsing the file.
Now as the file become huge and number of objects become very large my code is getting bad_alloc error as it is not finding any space avalable in the heap for allocating new object.
Is there any way to parse the file?
I'm currently curios with my python program which the basic goal is to parse the character in mytestfile;let's see the code
Code:
f=open('/home/andrewraharjo/Desktop/snort.log','r')
j=f.read()
[code]...
I don't think this is a "perl one-liner" of find and replace. I'm trying to auto-fill some information in a listing of files. The simplest example is that in the files the following exists:
I would want the script to find this and populate it with something like -- Date : 20101004-1758
I have a few more similar fields to autofill, and I'd like to do this from within a larger perl script I'm developing to process these files. So, how I perform in-place file modification from within a perl script?
When I parse a XML file, should I rely on the order of elements?
For example say we have:
Should I rely on the above order?
Would the following still be valid:
I'm trying to find out if a well formed XML document should have an ordered structure, or if it's still valid XML if it has no order.
I am trying to think of a logic where my file contains some data I had to read and do some processing. Issue is that file contains data multiple times. For example:
:::::::::::
var1=value1
var2=value2
[code].....
I have to read first paragraph of variables and do some processing and then move on until the end of file. Variable names are same in whole file but for each paragraph the value is different. I can't think of a logic to attain this task. How can I do it? It should be a simple bash script, but I am not able to work out.
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.
iḿ trying to parse a file using html parser by libxml.
Code: #include <stdio.h>
#include <libxml/HTMLparser.h>
#include <string.h>
void main(){
printf("main
");
[Code]....
copy string a to string b and change string b with toupper() and count the chars
View 3 Replies View RelatedI want linux command to parse a particular string or pattern in files that are in my home directory and its sub-directory.
View 4 Replies View RelatedMy script.
This is may script:
Code:
Problem: Output file doest not exclude the values in grep -av
I have script that I'm working on that updates a username in all the files that are called blah.inc for my framework. since i host a bunch of these web apps i need to do it to all of them. so I need to figure out how to update these files automagically with out me watching it to call vim every time. heres what I have so far
Code:
This finds the files but now i need to figure out how to do s/bob/fred/g on those files.
I have a file in which I have string called "already there" in some line of it. I want that if the string is present enter some loop..
like
if(( grep "already there" $file is true ))
then
--
--
fi
But the thing is when I make grep it gives the whole line in which this string is present and gives some error: if[ grep "already there" file ]: command not found. I am very new to shell scripting.
I've found some scripts that replaces a string in a file but it's not quite working for me.
And I'm trying to replace a tag in an xml file that looks like this
So I ran a command line like this perl -w -i -p -e "s/xmlns="'http://mydomain.org/replacethese.xsd'">/>/g" testfile.xml
And I get a error output
Search pattern not terminated at -e line 1.
Found the script from this blog [url]
I want to write some code to search for a specific string in a text file, but without using grep command.
View 5 Replies View RelatedI am trying to remove everything before my string code...
View 9 Replies View RelatedI know how to replace a particular instance (say 3rd one) of a word in a line using sed based on the sed one-liners. However I would like to replace a particular instance of a word in the entire file.
For example, here is a file:
Code:
John
Betty
Jack
Ron
Jack
Paul
So now I would like to replace the second instance of Jack (in red color) with "Rob" (for example). Not quite sure how to do that? I tried couple of things from here but they did not work.
I have question about replacing a string in a file.
How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?
I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.
Code:
function forcd
{
[code]...
Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.
username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1
If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:
Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *
[code]....
I want to know how can I add something to a specific line.. the output would be something like:
abc
def 123
ghi
Search for string "def" and add something to that line.