Questions tagged [file-manipulation]

219 questions
1
vote
1 answer

Ansible read files line by line and delete lines on condition

Am trying to read a file line by line and delete the line if certain conditions are met sample input file: abcd Sat Oct 25 04:30:35 EDT 2036 defg Tue Dec 01 18:59:59 EST 2037 ghij Fri Jun 17 06:15:06 EDT 2022 Expected output file: abcd Sat Oct 25…
1
vote
1 answer

Is there a way to delete or replace a character in a text file in c

I need to make a C program that removes empty lines as homework since we didn't study a way to removing characters from files my first attempt was to overwrite all the characters but both fprintf and fputc inserts characters. #include…
1
vote
2 answers

How to replace such column names whose next columns are having all nan values in Pandas

I have a file which has data separated with different spaces and column names are also having spaces. Type Dec LookupTable Field Name Field Len Start Pos NUM 0 _ sample data 5 …
Arya Stark
  • 205
  • 1
  • 11
1
vote
1 answer

Running into issues getting os.rename module to work for automation script

Im looping through a file with multiple log files that have been assigned a randomized filename. The script should search within the log for the line containing "hostname" and then pull out the assigned hostname to use as the re-assigned file name,…
1
vote
1 answer

How can I use Perl for in-place-editing of files with Unix-EOL on Windows?

I am trying to use Perl's in-place-editing feature to change some text in files with Unix line endings in a PowerShell session on Windows: perl.exe -i'.bak' -p -e "s#PATTERN#REPLACEMENT#g" (get-childItem *.sql,*/*.sql) Unfortunately, the line…
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
1
vote
1 answer

Adding folder name as a prefix to file name in R

I would like to add the folder name in front of all file names being in this folder. My folder name is TempAir, all file names within this folder are "201401.tif" "201402.tif" "201403.tif" "201404.tif" "201405.tif" files.old <- list.files(path =…
1
vote
1 answer

Is there a PowerShell equivalent of `paste` (i.e., horizontal file concatenation)?

I want to horizontally concatenate a bunch of CSV files using PowerShell. (When considering possible "duplicate" questions", please not that "a bunch" is not "two".) What is the PowerShell equivalent of the Linux paste command?
Alan
  • 9,410
  • 15
  • 20
1
vote
1 answer

How should do you update JSON values of keys which are themselves values, with python

I have 2 files, one a test.json and the other my test.py My goal is to have the value of the key "test3" update and instead of being equal to a 3(like how it is shown below), update and turn into a 10. Here is the test.json { "test": { …
1
vote
3 answers

How to reliably handle files uploaded periodically by an external agent?

It's a very common scenario: some process wants to drop a file on a server every 30 minutes or so. Simple, right? Well, I can think of a bunch of ways this could go wrong. For instance, processing a file may take more or less than 30 minutes, so…
user73774
1
vote
1 answer

Lossless manipulation of JPEG in C++

I have a JPEG file on disk which is not quite normal - this JPEG file has additional rubbish data appended behind End Of Image (FFD9). This JPEG file can still be opened by JPEG viewers though. I wish to remove those additional information behind…
seveleven
  • 697
  • 2
  • 13
  • 21
1
vote
1 answer

Update PHP file constant from C#

I need to update a constant defined in a PHP file. The constants.php file is quite simple: Now what I need is for my C# application to update the $updatedOn constant…
Jim
  • 505
  • 3
  • 13
1
vote
0 answers

PyLint detect undefined variables that are defined and used in if statement or with ... as statement inside a class definition

I was doing some analysis about the Coronavirus and PyLint detect some undefined variables that are defined in an if statement or by a with statement. my code work as expected and is see no errors or runtime warnings. Here's my code : import…
1
vote
0 answers

How to swap rows and columns in a very large file using java

In Python, we can use iterator(generator function) on the file and finally use zip() which maps similarly indexed columns and write those columns as rows in a new file. Here is an example: f=open('inp.tsv') lines = (line.strip().split('\t') for line…
money
  • 11
  • 2
1
vote
3 answers

How to print certain lines from sections of a file separated by a blank line with sed

I have been trying to come up with a sed command that will pull certain lines from blocks of text separated by a blank line in a file. The blocks of text are as below. # cat test_file.txt line 1 line 2 line 3 line 4 line 5 line 1 line 2 line…
chrisdow38
  • 15
  • 5
1
vote
3 answers

How to create an undeletable file in Delphi

[the following is a rephrase of my previous question, which was deemed ambiguous]. I'm digging into creating a basic licensing mechanism for a demo application. What I have in mind goes like that: the application creates an empty "license file"…
Bogdan Botezatu
  • 579
  • 1
  • 9
  • 25