file-manipulation

Delete last line break using sed [duplicate]

旧时模样 提交于 2019-12-02 05:42:02
问题 This question already has answers here : How can I delete a newline if it is the last character in a file? (22 answers) Closed last year . 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. 回答1: Why is sed printing a newline? When you read the sed POSIX standard, then it states: Whenever the pattern space is written to standard output or a named

How to use “append” command on specific position in a text file using Visual Basic?

倖福魔咒の 提交于 2019-12-02 05:38:45
Text file: test1 test2 test3 test4 I want to write after "test2" - something. I tried first time to open the file and I read the position where is test2. After that I opened the text file in Append format but I don't know how to write on specific position. I must to use next commands or others in Visual Basic: for reading from a text file: Open Test_Filename For Input As # for appending in a text file: Open Test_Filename For Append As #3 Any helps will be great. Edit: LineNum = 1 LineRead = 0 Test_Filename ="path/test.txt" If Len(Dir$(Test_Filename)) = 0 Then MsgBox ("Cannot find the file")

Copying specific files from multiple sub-directories into a single folder in R

我们两清 提交于 2019-12-02 05:15:02
Assuming I have 3 folders with a large number of files in each, I want to select only a few files from each sub-directory and paste only those files into a new folder. Let's call the 3 folders: desktop/dir/sub_11s_gi01_ab desktop/dir/sub_11f_gi01_b desktop/dir/sub_12s_gi02_ms The files that need to be copied have the extension ".wang.tax.sum" All of the other files cannot be copied and then deleted because it would take days. From other questions, I can combine all the files into a list and copy all of them but I don't know how to copy only the files that end with .wang.tax.sum I can use the

Renaming files during ANT copy

烈酒焚心 提交于 2019-11-30 06:48:53
I'd like to copy a directory of files, and rename some of them in the process. When I run the script below, nothing copies. If I comment the glob mappers in the file below, the files are copied (without the renaming) Thanks for any help. James <?xml version="1.0" ?> <project name="Create project structure" default="main"> <target name="main" description="Copy template files to project folder"> <echo>Copying template files to project folder</echo> <copy todir="${project.dir}" verbose="true" overwrite="true"> <fileset dir="${shared.files}/templateproject" excludes=".svn"/> <mapper>

Python: How to move a file with unicode filename to a unicode folder

随声附和 提交于 2019-11-29 10:26:34
I'm having hell with moving a unicode named file between unicode named folders in a Python script under Windows... What syntax would you use to find all files of type *.ext in a folder and move them to a relative location? Assume files and folders are unicode. The basic problem is the unconverted mix between Unicode and byte strings. The solutions can be converting to a single format or avoiding the problems using some trickery. All of my solutions include the glob and shutil standard library. For the sake of example, I have some Unicode filenames ending with ods , and I want to move them to

How to add extra meta data to PNG?

爷,独闯天下 提交于 2019-11-29 07:34:13
is there a way to add some extra metadata to a PNG file and then retrieve it with PHP ? like Comment field. If you have ImageMagick installed, it comes with two utilities: mogrify and identify. To add comments: $ mogrify.exe -comment "My test comment" plogo.png To retrieve comments: $ identify.exe -verbose plogo.png | grep -i "comment:" comment: My test comment I don't know if mogrify/identify functions are available as PHP libraries, but you can always use the php system command. 来源: https://stackoverflow.com/questions/4497206/how-to-add-extra-meta-data-to-png

Renaming files during ANT copy

纵然是瞬间 提交于 2019-11-29 06:39:43
问题 I'd like to copy a directory of files, and rename some of them in the process. When I run the script below, nothing copies. If I comment the glob mappers in the file below, the files are copied (without the renaming) Thanks for any help. James <?xml version="1.0" ?> <project name="Create project structure" default="main"> <target name="main" description="Copy template files to project folder"> <echo>Copying template files to project folder</echo> <copy todir="${project.dir}" verbose="true"

How to insert a line in a file between two blocks of known lines (if not already inserted previously), using bash?

无人久伴 提交于 2019-11-27 07:03:25
问题 I wrote a bash script which can modify php.ini according to my needs. Now I have to introduce a new change, and I cannot find a clear solution to it. I need to modify php.ini in order to insert (if not already inserted previously) extension="memcache.so" between the block ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; and the block ;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;; possibly just before the second one. Can anyone help me please? Thanks in advance