FAQ Database Discussion Community


File Handling and making directories to match in bash

bash,shell,sorting,matching,file-handling
I have these files: File_1.2.txt, File_1.5.txt, File_2.3.txt, and File_4.7.txt. I want to make directories for them and sort them into the directories, like below. Dir_001 -> File_1.2.txt File_1.5.txt Dir_002 -> File_1.2.txt File_2.3.txt Dir_003 -> File_2.3.txt Dir_004 -> File_4.7.txt Dir_005 -> File_1.5.txt Dir_007 -> File_4.7.txt So a directory is made for...

Using a bash script to apply another script to every file in a directory like a matrix

bash,shell,matrix,scripting,file-handling
Let's say in my directory I have five files. Files: 1,2,3,4, & 5 I have a script that will do a mathematical process to compare two files and I want to use this script on every file in the directory, example below. compare file 1 to 2,3,4, & 5 compare...

read data from text file and filter content

java,file-handling
I have a text file which has some securities market datas i want to read the content of the file up to now i am able to read the whole content but what I need is read perticular lines not whole content and i want to store that perticular line...

c file handling : unable to write after 25 y?

c,file-handling
#include<stdio.h> main() { FILE *p,*q; char b; int a; p = fopen("three", "w"); for(a=1; a<=50; a++) fprintf(p, "%c", a); fclose(p); q = fopen("three", "r"); while(!feof(q)) { fscanf(q, "%c", &b); //dont print after 25! ? printf("%d",b); } fclose(q); } The question is why it does not print after 25. I tried...

counting the number of times a character appears in a file in a case insensitive manner using C language

c,file-handling,case-insensitive
The problem statement : a C program to count the number of times a character appears in the File. character is considered Case insensitive. I have converted both the input character and character from the file to upper case so that none of the occurrence of the character goes uncounted....

File handling in getline function

c++,getline,file-handling
I have a text file that looks like this: A 4 6 B 5 7 c 4 8 I want to store it in three different arrays: char pro[]; // contains values A B C int arrival[]; // contains values of 4 5 5 int Burst[]; // contains values of...

Linked List, Stuck on file management

c,linked-list,file-handling
I am trying to read from a file called data.txt. and store it into a LL which looks like this Quanta 2 New 2 Ready 2 A 1 3 B 3 4 C 5 6 D 7 9 I would like to read that file, one line at a time,...

Using Gawk and Printf in a Bash script

bash,scripting,printf,file-handling,gawk
I am trying to separate a file into smaller files with gawk and rename the smaller files in order from the original file. for i in *.txt do gawk -v RS="START_of_LINE_to_SEPARATE" 'NF{ print RS$0 > "new_file_"++n".txt"}' $i done The output gives me: new_file_1.txt new_file_2.txt ect... I would like the output...

Remove trailing white-spaces from each line in a file

ruby-on-rails,ruby,file-handling
I am using ruby and I want to remove trailing white-spaces at the end of each line in a file. One way to do this, iterate line by line and save it in another file and then replace new file with the old one. temp_file = Tempfile.new("temp") f.each_line do |line|...

Map filled with file names and set as request attribute by servlet appears empty in JSP

jsp,servlets,hashmap,file-handling
I'm creating a blogging system for a project (academic). I have a problem where I need to pass a map (LinkedHashMap) to a jsp file. But browser shows Nothing. Here's my code: public void doService (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = "localhost:8080/YouBlogger/Posts/"; File dir =...

Save Arraylist to file android

android,arraylist,file-handling
I'm doing my first Android app here and I'm trying to write an ArrayList<String> to a file, and read it back. Here's my code to write the file: (Class is called SaveFiles) public static void writeList(Context c, ArrayList<String> list){ try{ FileOutputStream fos = c.openFileOutput("NAME", Context.MODE_PRIVATE); ObjectOutputStream os = new ObjectOutputStream(fos);...

Write output of android shell command to a file

android,android-manifest,file-handling,systrace
I am trying to write output of atrace to sdcard. I am using getRuntime().exec()("atrace gfx > /storage/sdcard0/trace.txt") in the app.App is signed as a system app and the command is working fine from terminal.But no file is created when running it from the app.

How to make excel backup checker script get file with newest date

vba,excel-vba,file-handling
I have a program that creates backups after format: <name>_<date> Some of them have more backups, some of them have none. There are kept up to 3 backups with same name but different dates. I have an excel table that contains names and a script that checks if there is...

How to call a system file selection dialog using perl on windows?

perl,file-handling,filehandle,filehandler,fileopendialog
I know many perl based gui module would do that easily but I am curious about methods other than Prima or Tk etc. I want to call this dialog (Exactly looking as Windows Explorer) for a command line package. Is anything similar to system(''); command possible. Pls Mind that, I...

VBA 7.0 in Excel, Line Input appears to add extra quotes around the line

excel,vba,excel-vba,file-handling
I have a file with lines like: one two three When I read from one file and write to another, they end up quoted. They are also quoted within the variable in the watch window. Also when I have a file with: "one", "two", "three" It ends up written as:...

How do we get text from a file (word-by-word) into a 2D array in PHP?

php,arrays,parsing,file-handling
I have a text file with some stuff that I would like to put into a 2D array. That text file comprises of sentences of equal length. How do I put each word into an array? Example of text file is - This is stackoverflow I am user This file...

Load a large text file into a string

c#,string,file-handling
I'm looking to load a 150 MB text file into a string. The file is UTF16 encoded, so it will produce a string that's about 150 MB in memory. All the methods I have tried result in an Out of Memory exception. I know this is a huge string, and...

PHP Search Not Matching Line in File

javascript,php,file-handling,strpos,comparison-operators
Just creating a simple login system for a school club. And I am trying to send an error if the name that is entered does not match any line in the file containing student names. The file looks a bit like this: Student One 8M2 Student Two 8M3 Student Three...

How to remove a particular word from a text that satisfies a condition?

java,file-handling
I have a text file with lots of words. I'd like to remove words that contain repetitive letters(eg. zoos - contains 2 o's). What is the best way to do this ?

What is ios::in|ios::out?

c++,file-handling
I was reading some project code and I found this,here MembersOfLibrary() is a constructor of class MenberOfLibrary class MembersOfLibrary { public: MembersOfLibrary(); ~MembersOfLibrary() {} void addMember(); void removeMember(); unsigned int searchMember(unsigned int MembershipNo); void searchMember(unsigned char * name); void displayMember(); private: Members libMembers; }; MembersOfLibrary::MembersOfLibrary() { fstream memberData; memberData.open("member.txt", ios::in|ios::out);...

fstat() return 0, with file size 0 and errno 11

c,linux,file-handling,fstat
I'm trying the following thing in my code:- { int y,n_bytes; struct stat temp_data; y = fstat(netdev->queue_fd[class_id],&temp_data); printf("Success - %d , size -> %lld , Error- %d \n",y,temp_data.st_size,errno); n_bytes = write(netdev->queue_fd[class_id],buffer->data,buffer->size); y = fstat(netdev->queue_fd[class_id],&temp_data); printf("After write Success - %d , size -> %lld , Error- %d and the value of...

PHP write contents to file with user submitted data [duplicate]

php,file-handling
This question already has an answer here: What is the difference between single-quoted and double-quoted strings in PHP? 9 answers I am trying to write contents to a file with user submitted data. I have some text say "my name is" and after this text i want to write...

Why does tellp() return 0 for ios::app but not for ios::ate?

c++,file-handling
I have the following code snippet : ofile.open("New1.dat",ios::app|ios::binary|ios::ate); long bytes = ofile.tellp()/sizeof(t); cout<<ofile.tellp()<<endl; //line 1 t.input(bytes); ofile.write((char *)&t,sizeof(t)); ofile.close(); When I remove ios::app or ios::ate, the output of line 1 is 0, howeever only when both of them are together, they give the correct file location. Why does this happen?...

Python context for file or None

python,file-handling,with-statement
Python is going to call a subprocess, the user either requested that subprocesses stdout is to go to a file (or back-holed to os.devnull), or the subprocesses output is to be passed though "in real time". My current best guess as how to do this would seemingly work: Let file_path...

Error in Downloading large files from Server using Java

java,file,file-handling
I am new to File handling in Java. I have written a code which should download a file from the server. The code is working for files upto size 70 MB.If large files are downloaded it throws an Exception. SRVE0260E: The server cannot use the error page specified for your...

File Handling Error in C

c,file-handling
I am learning file handling in C.I have this code but it is not accepting string as an input to write it to a file.Any help will be appreciated. #include<stdio.h> #include<string.h> #include <stdlib.h> int main(void) { FILE * fp1; fp1 = fopen("abc.txt","a+"); if(fp1==NULL) {printf("An error occurred"); } printf("Delete file?\n"); int...

How to reset $.?

perl,file-handling
I know $. shows the line number when $/ is set to "\n". I wanted to emulate the Unix tail command in Perl and print the last 10 lines from a file but $. didn't work. If the file contains 14 lines it starts from 15 in the next loop....

C# Scoreboard .txt scoreboard making for a tetris game

c#,linq,sorting,io,file-handling
I am making a Tetris game in c# console. I have done most of the game but i am stuck with file handling. I haven"t really found anything related to this so i tought i might give it a shot and ask it. So what i am trying to do...

Unexpected traceback on text file in Python

python,file-handling,traceback
I'm experiencing a "Traceback (most recent call last):" error when I try to write to a text file using this code. All three files already exist (although I believe they shouldn't have to - the code should create them if it cannot find them, should it not?), and they are...

How to create sub string in a line read from text file separated by comma

javascript,ajax,regex,file-handling
I am java script newbie and i have a text file like this Address.txt : Andhra Pradesh,East Godavari,Reach within 36 Hrs Andhra Pradesh,Guntur,Reach within 36 Hrs Andhra Pradesh,Krishna,Reach within 36 Hrs Andhra Pradesh,Visakhapatnam,Reach within 36 Hrs Andhra Pradesh,Chittoor,Reach within 36 Hrs Now i want to separate each loine by substring...

separate a particular chunk of line through file handling [duplicate]

c#,file-handling
This question already has an answer here: Reading CSV file and storing values into an array 10 answers I am using c# to access a text file through file handling. I want to go through all the lines and separate a particular chunk from each line e.g col1 col2...

Compare consecutive columns of a file and return the number of non-matching elements

python,file-handling
I have a text file which looks like this: # sampleID HGDP00511 HGDP00511 HGDP00512 HGDP00512 HGDP00513 HGDP00513 M rs4124251 0 0 A G 0 A M rs6650104 0 A C T 0 0 M rs12184279 0 0 G A T 0 I want to compare the consecutive columns and return...