Questions tagged [file-manipulation]

219 questions
2
votes
3 answers

Remove bytes in the middle of a file without moving the end?

For example if i have lots of data entry's stored in a file, each with different sizes, and i have 1000 entries which makes the file like 100MB large, if i then wanted to remove an entry in the middle of the file which is size of 50KB, how can i…
Kaije
  • 2,631
  • 6
  • 38
  • 40
2
votes
2 answers

Using PowerShell, how can I add a file to a newly created file collection?

How do I create a blank file collection then add a file to it? This is the pseudo-representaion. $filelist = get-childitem "c:\somefolder\*" $keepfiles = new-object psobject #???? $purgefiles = new-object psobject #???? foreach ($file in…
Mouffette
  • 732
  • 1
  • 7
  • 19
2
votes
2 answers

bash delete directories based on contents

Currently I have multiple directories Directory1 Directory2 Directory3 Directory4 each of these directories contain files (the files are somewhat cryptic) what i wish to do is scan files within the folders to see if certain files are present, if…
Rk_23
  • 193
  • 1
  • 8
2
votes
1 answer

Merge different text files into one Excel file, and delete first column of all but first

I need to merge different text files (.sav files) into one Excel file (output.xls), but starting from the second input file onwards, I want to exclude the first column present in each file. What I want to obtain is the following (with placeholder…
2
votes
1 answer

Text manipulation problem - how to replace text after a known value

I have a large text file containing filenames ending in .txt Some of the rows of the file have unwanted text after the filename extension. I am trying to find a way to search+replace or trim the whole file so that if a row is found with .txt,…
AndyR
  • 31
  • 2
  • 6
2
votes
2 answers

File Manipulation with pandas

I am a beginner in manipulating files, hence I haven't got a full grasp of it. What I want to do is, by using pandas, create a new file that has all the elements of a previews one listed based on their price in descending order. This is my…
Klaiv_Mrt
  • 21
  • 5
2
votes
1 answer

PowerShell script to update config file based on env variables

I am new to PowerShell and trying to accomplish few things here: I have a zabbix agent configuration file and I want to be able to change the zabbix_agent_win.conf. Hostname ServerActive HostMetaDataItem My ultimate goal is to be have a…
Katherine
  • 33
  • 1
  • 4
2
votes
4 answers

Delete last line break using sed

How to delete the last \n from a file. The file has a last blank line created for a line break in the last text line. I'm using this command: sed '/^\s*$/d' But that las blank line is not removed.
Carlos
  • 131
  • 3
  • 13
2
votes
1 answer

Basic PHP file manipulation

Apologizes for such basic question, but I've gone mad debuggind the following code: $fname = 'results.txt'; $handle = fopen($fname,"a+"); if ($handle){ $cnt = file_get_contents('./results.txt'); $pos = strpos($cnt,":"); if ($pos ===…
Arnthor
  • 2,563
  • 6
  • 34
  • 54
2
votes
3 answers

Python 3.6: Looping through files in os.listdir() and writing some of them to a text document

I'm trying to loop through some files and write the file names of the .txt ones to another .txt the piece of code stops after finding and writing the name of one file. how would I get it to write the names of the rest? import…
Charlie-5
  • 43
  • 1
  • 5
2
votes
2 answers

How to find the first and last occurrence of a field from a log file?

I have a log file which contains execution start times and end times of various threads. I have done half the work, but I need some help to finish the other half. I wrote this command- cat 2017-05-15.log | grep 'Executing ETL' | tr -s ' ' | cut…
RodrikTheReader
  • 757
  • 1
  • 9
  • 22
2
votes
2 answers

Split and add text/number to the filename

I have been trying to write a script to remove end part of the filename and replace it with a version number of a build. I have tried trim and split but because of extra dots and not good with regex, im having problems. These are file…
spiceitup
  • 132
  • 10
2
votes
1 answer

Any reason why an std::ofstream object won't close properly?

I noticed in my C++ code that anytime I close an std::ofstream object I'm unable to reopen the file I closed with std::ifstream. std::ifstream's open function will always fail. Is there anything 'extra' I can do to ensure that my std::ofstream…
Rob S.
  • 3,599
  • 6
  • 30
  • 39
2
votes
4 answers

Convert vertical text into horizontal in shell

I just pondered upon this problem while executing some tasks in shell. How can I convert a .txt file which contains text in the following format[vertical direction]: H e l l o W o r l d Note: The line without any letter contains a space and…
Liju Thomas
  • 1,054
  • 5
  • 18
  • 25
2
votes
1 answer

Batch file to remove data from a file

I am trying to remove any data from a file after the entry [TEST] E.g. The text file is: Random Text 1 Random Text 2 Random Text 3 [TEST] Random Text 4 Random Text 5 Random Text 6 .... After I run the batch file I just want it to remove any data…
Rob
  • 151
  • 1
  • 2
  • 11
1 2
3
14 15