Programming :: Prepend To ASCII Text File In C?

Jun 15, 2010

To start off I would like to acknowledge that I am not a very good C programmer and pretty much everything I know has been self taught through mostly trial and error. So forgive me if there is an obvious answer to my question, or if I don't immediately grasp the concepts involved in the possible solution.

Basically, I'm writing an application which will be creating log file entries rather rapidly (potentially hundreds per minute), and I would like each new line to appear at the top of the log file, rather than the end. Opening a text file in append mode is easy enough, but I can't seem to find any obvious way to do the opposite.

I have been looking online and it seems that there exists no standard way to do this, and I have only been able to find a few mentions of how somebody might achieve it. The most common method seems to be using two files and copying the data back and forth between them. This seems like it would be insanely I/O intensive with the number of lines I'm likely to be generating. If this is the best method to use, I will give it a shot; though I am not 100% clear on how to implement it, I am also open to any other ideas as to how to accomplish this, and I don't have to worry about portability since the program already uses Linux-only libraries. So calling out to sed or something is not necessarily out of the question (though I imagine performance would also be an issue there).

View 4 Replies


ADVERTISEMENT

Programming :: Bash - To Prepend Text To Variable

Feb 13, 2010

The output of following code is not like it's intended ...

Code:

This is the output:

Code:

Test prepending ...apple is a nice word, hour is a nice word, But of course what I want to do in the first set of commands is to prepend the word "an" to the words "apple" and "hour" in the for-loop.

View 4 Replies View Related

CentOS 5 :: Convert Between "ASCII English Text" And "ASCII Text"?

Aug 3, 2011

This is weird, and I never noticed before, but now I have an application that is borking on weird things like when /etc/hosts is of one file format or another, and I don't even know the difference between the two (google doesn't tell much either). on CentOS 5.5/5.6 x86_64: a which on the following is an interesting tell:

vi = /bin/vi
vim = /usr/bin/vim

both are actually vim version 7.0.237 but sum differently, and although they are both actually separate executables in the stock installs of CentOS I've been building, on most distros, and older versions of CentOS it seems, vi is usually just a symlink to vim - but again, not in these fresh installs it seems. When I create a file with the 'vi' above, it defaults (usually) to "ASCII text" (but not always) When I create a file with the 'vim' above, it defaults to "ASCII English text" (and causes a particular application I'm working with to bork and barf). It seems the OS is installed by default yielding both file types too, as evidenced by the following:

[Code]...

View 4 Replies View Related

Programming :: Convert Multiple File In Directory - Ascii To Hex In Perl ?

Apr 9, 2011

I have found a perl script that can convert single file: ascii to hex.

However I have thousand of file that I want to convert from ascii to hex.

Here is the perl script that convert single ascii file to hex in single line:

Quote:

So I would like to read multiple file from a directory.

Then the file will be have same name file with hex data.

Here is sample of the read and write directory file.

Quote:

View 3 Replies View Related

Software :: Can't Prepend Subdir Name To Each File?

Jun 24, 2011

To investigate an issue, I need to tarball all the files in a sub-directory without prepending the name of the subdir to each file. For instance, I do notwant tar to include MYSUBDIR:

Code:
/tmp# tar czvf package.tar.gz MYSUBDIR
MYSUBDIR/
MYSUBDIR/file1
MYSUBDIR/file2
I tried "-C MYSUBDIR", or "tar cvPf", but tar always includes the path to the files.

The only way I found is to "cd MYSUBDIR" before running "tar cvf".

Is there a way to tell tar to exlude the subdir name?

View 7 Replies View Related

Programming :: Remove Lines In A Text File Based On Another Text File?

Jan 28, 2009

I have a text file called file1.txt containing many lines eg.

line1
line2
line3
line4
line5
line6

Then i have another text file called file2.txt contains

3
5
6

Is there a command to remove the lines in file1.txt based on the keywords in file2.txt? note: It should remove line3,line5,line6 based on 3,5,6

View 10 Replies View Related

General :: Convert Text To ASCII?

May 20, 2010

how i can convert a text to ASCII? >>> ( to encrypt the text ) and how can we use the "hexdump"

View 5 Replies View Related

General :: Command Line To Prepend 8 Bytes Of Data To A Binary File?

Jan 14, 2011

i would like to add 8 bytes of data to the begigning of a binary file.is there a command for this?

View 2 Replies View Related

Programming :: Adding Lines Of Text To Beginning Of Text File

Jan 19, 2009

I need to insert 3-4 lines of text to the beginning of a text file. The file is a largish MYSQL dump, the result of a backup shell script. This shell script should insert the required text.I've wrestled with sed, but lost.

View 2 Replies View Related

Programming :: Delete Line Of Text From Text File Via Shell?

Jan 13, 2010

I have to delete a certain line of text from the a textfile via ubuntu's shell scripting.I have done research, and it seems that most people advocate the usage of sed /d option. sed makes does not edit the text file. Hence, most options I discovered involved the use of a temporary variable/textfile and then overwriting the old file with the temporary new file. Is there anyway whereby I can bypass the use of temporary storage containers? I hope there is any magical combination of commands to edit the file directly.

View 3 Replies View Related

Programming :: Exporting Glade Text View To Text File?

Jan 8, 2011

I want to display something in my text view widget in glade using c code. that's all right.
now I need to attach a save button beneath the text view.so that on click the text view content should save as a txt file..

View 8 Replies View Related

Programming :: Formatting Fields And Text Being Displayed From Text File?

Feb 9, 2011

I want to display the contents of a particular log file (simple text file, I mean in Linux). But there is a problem: The contents need to be organized in a fixed format. Have a look at this log file:

sampleLog.txt

Code:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

So, while displaying the contents of above file on a web page, I want to format the field names found in the log file: User Name:, Reported Problems Description:, and Remarks:. These fields may contain a variable length of text and no specific line number is assumed for them to appear on.

The desired output should look like this:

User Name: XYZ
Reported Problems Description: Blah! Blah! Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah! Blah!Blah!

[code]....

Well, what I am trying to do may sound wierd to some of you. The filed "Reported Problems Description:" can possible contain text which embeds colon (.

View 15 Replies View Related

General :: Text To ASCII Art Command Line Tool?

Oct 24, 2010

I want a command line tool that echoes a string in ASCII art way, like here.

View 2 Replies View Related

General :: Convert Binary Number To Text/ascii?

Mar 16, 2011

is there command in linux which is able to convert binary (0101001010000100) to text like it means something

View 4 Replies View Related

Programming :: Add Text Before Line Number In Text File?

May 3, 2010

a sed command to add a text before line number in text file? I have text file with 500 lines, and i want to add 3 more lines with text after line 300, OR before line 302, isn't no problem.

View 16 Replies View Related

General :: Convert Binary File In To Ascii File Using Shell Script?

May 23, 2011

i am trying to convert a binary file in to ASCII using shell script. this file contains multiple types of data like string, number, bcd, etc.

View 5 Replies View Related

Programming :: Script To Copy Paste Text From One File To Another (overwriting Part Of The File)?

Apr 19, 2011

I have a .txt-file with ~50.000 lines of numbers, generated by a mathematics program. From this file, I need line ~ 1.100 to line ~16.000 (these lines are always the same btw, this may make the solution easier, dunno) to be copy/pasted to another file, where the lines ~500 to ~15.000 (also, every time the same) should be overwritten by the aforementioned lines...I haven't found or come up with anything that works yet, mostly I find solutions to copy everything from one file to another but I can't find something to specifically overwrite a part of a file with part of another.

View 4 Replies View Related

Programming :: Create A Duplicate File Of A Text File In PHP?

Nov 11, 2010

What I plan to do is, create a duplicate file of a text file, and then append some text into the new text file.

View 1 Replies View Related

Programming :: Filter ASCII Characters PHP?

Mar 8, 2010

How can I filter ASCII quotes( ' ) and double quotes ( " ) so that I can replace them with the UTF-8 equivalent?If I copy text from a Word Document(ASCII), and upload it to a web page with PHP. The Database(UTF-8) will replace these racters with incorrect character(s).I need some function that will replace these characters but I don't know how to differentiate the ASCII quotes and the UTF-8 Quotes without (somehow) converting the string to hex, then preg_replace'ing the hex code for the symbol.

View 8 Replies View Related

Programming :: Not Reading Non-ASCII Characters

Apr 26, 2010

Well, I have a web application in Linux server. All my Java codes are there. FYI, whenever user entered non-ASCII characters(e.g. ∞,�,�) in a text field in my web application, and I check the log of my Java code in Linux server, it returns weird characters.

Suppose user entered ∞ in the text field. I should get ∞ in my log too. However, I got weird characters in return.

View 14 Replies View Related

Programming :: Print All ASCII Characters In C#?

Mar 9, 2011

i want to print all ASCII characters kind of like a table, but i really don't have an idea of how to do it, i don't know if there is a built-in method or something to accomplish this, if not

View 2 Replies View Related

Programming :: Qt Conversion From Ascii To QString?

Aug 25, 2010

I'm working on a Qt program and when it gets to the following line of code I get a seg fault:

QString blah = QString::fromAscii(entry->d_name, 256);

entry->d_name is a 256 byte character array returned by readdir(), I would expect this line of code to convert that character array from ascii to a QString, but I get a seg fault and I'm not entirely sure why..

View 2 Replies View Related

Programming :: Output Data To An Ascii Table?

Oct 18, 2010

I've got lines of data in the following format:
space1=number of times error has occured
space2=IP address
space3=Error

I've set this out nicely with printf and made it email me, the problem is - it's not entirely clear what each column/space is and the IP and occurances can sometimes seem confusing. Is there any (easy) way to output this into an ascii like table? There will always be 5 occurances, and the format will always be the same

View 1 Replies View Related

Server :: Convert A Hex File To An ASCII File?

Sep 8, 2010

I have a file of 2GB size in hex form. This is a log file from the server which I converted to hex as the file got corrupted.Can anyone tell how to convert this hex file to ASCII?

View 1 Replies View Related

Programming :: Checking Function - Character ASCII Or Unicode

Jan 20, 2009

To know the function on checking whether a character is ascii or unicode character. From the following [uRL]. The function IsTextUnicode is related to Windows VC++ library. I would like to know the library/function which provides such facility.

View 2 Replies View Related

Red Hat :: Convert A Unicode File To Ascii?

Jul 1, 2010

I need to be able to convert a unicode file to ascii using red hat.

View 1 Replies View Related

Programming :: Getting Table Name From A Text File?

Mar 11, 2011

I have been working on this since 3 days but wasn't able to achieve what I want

I have a big text that has the following format:

Current max fieldLen for table1 (a):
Fld# Width MaxWidth ERR NAME
---- ------ -------------- ------ ---------
2: 80 38 *** field-name
3: 4 2 field-version
4: 40 7 field-value

[Code]....

View 7 Replies View Related

Programming :: Add A Column To A Text File?

Apr 28, 2011

I have a text field that is just list of servers and I need to add the word hostname in front of them... It must be brain fart but I can't think of how to do this. Basically I need this:

server1
server2
server3

To this:

hostname server1
hostname server2
hostname server3

(And I just mean simply the word "hostname")

View 2 Replies View Related

Programming :: Sed And Rename Text In File?

Feb 10, 2011

I need a sed and renaming the text in file. we have this one:

Quote:

Originally Posted by nickname
nickname presents: $subject
Size: size

[code]....

View 2 Replies View Related

Programming :: Add HTML Formatting To Text File?

Jun 30, 2010

I need to extract som text from a text file. The text is a test log with system info at the top and results further down. What I need is to add different tags with formatting before and after each line. I have prepared a template with html formatting, but the number of lines in the test log may be different from case to case, so I need to be able to add formatting tags by need. Can this be done using bash script, sed, awk, head, tail... ?

View 4 Replies View Related







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