New lines after grep a binary file are missing - extract

Im trying to get text from text layers in a PSD file, under linux.
Now Im using:
egrep -a 'LayerText' file.psd
<photoshop:LayerText>免费获得宝贵资源! \ 工业现场过程仪表校准测试和维护诊断的必备工具 福禄克过程校准器,为工作在过程行业的技术工程师,自动化系统维护和仪表工程师,质量控制工程师,计量人员提供全面的工业校准测试和维护诊断工具:包括智能认证校准器,多功能信号校准器,压力校准器,温度校准器,环路校准器以及其他过程信号故障诊断和检测工具。FLUKE过程校准及检测工具,在化工、电力、石油、纸浆、食品饮料、制造业和污水处 理/给排水等行业的现场校准及检测维护方面处于世界领先水平。过程校准的全系列产品,从简单的回路校准器到复杂的文档化全功能过程校准器,可以提供各种必需的温度、压力、电流、电压以及电阻和频率的校准。来自福禄克750系列的校准管理软件,更是满足了用户 日益增长的对现场仪表校准数据进行归档整理的需求</photoshop:LayerText>
But using Photoshop the text layer has new lines after:
免费获得宝贵资源!
工业现场过程仪表校准测试和维护诊断的必备工具
How can I parse and output the text separated by real newlines and not all in one single line.
Thanks in advance.

It looks like your file does not contain a regular newline character but something else (looks like two spaces around a backslash).
If you want to separate the files using this (which looks like unusual) line separator, you can do that e.g. using sed(1).

Related

How to convert lines of text to JSON Lines?

If you have a text file with many lines of text, is there a readily available way to convert it into the JSON Lines format?
Example text file contains:
This is the first line.
This is the "second" line.
This is the \third/ line.
This is the {fourth} line;
Example JSON Lines (.jsonl) file:
{"text": "This is the first line."}
{"text": "This is the \"second\" line."}
{"text": "This is the \\third\/ line."}
{"text": "This is the {fourth} line;"}
I was hoping there is a simple way to sort of linearly transform it like this, while escaping the special characters for JSON. Are there online or (CLI) tools for the Mac that can do this?
A browser is the most handy way to access an interpreter nowadays. Here's a quick solution based on that:
Copy and paste your lines into this page: https://codebeautify.org/javascript-escape-unescape
Then copy the escaped string, press F12 on a modern broser and paste the following code:
console.log(JSON.stringify("***PASTE HERE**".split("\n").map(x => ({text: x}))))
Then delete ***PASTE HERE*** and paste the escaped lines. Press enter and you'll have a JSON output similar to what you want.

File composition using command line tools (Linux / Mac)

I have a file containing some text and some kind of placeHolder, and another file with some other text
Eg:
myText.txt:
some text strings plus a {{myPlaceholderText}} and some more text
myPlaceholderText.txt:
more text here
I want to be able to create a 3rd file containing the string:
"some text strings plus a more text here and some more text"
Is it possible to do that using command line tools?
I think sed is the easiest way to do it:
$ sed "s/{{myPlaceholderText}}/$(<myPlaceholder.txt)/g" myText.txt
some text strings plus a more text here and some more text
Yes. And bash is the safest common tool besides interpreted languages.
#!/bin/bash
R=$(<myPlaceholderText.txt)
while read -r LINE; do
echo "${LINE//'{{myPlaceholderText}}'/$R}"
done < myText.txt > another_file.txt
Output to another_file.txt:
some text strings plus a more text here and some more text
Another through awk:
awk 'BEGIN{getline r < ARGV[1];ARGV[1]=""}{gsub(/{{myPlaceholderText}}/,r)}1' myPlaceholderText.txt myText.txt > another_file.txt

Insert same code around different filenames

I am making a small online database that is accessible through the form of checkboxes for download. I was wondering if there was some way to list all of the filenames available for download in Sublime Text 2 and insert the same code around each filename?
Everything is functional, it would just save me a lot of repetitive copy and pasting if there is a faster way to do this.
Use SublimeText Find & Replace. Click the Regex button (it looks like a * to the left of the search box)
In the Find box, insert: (^.*$)
In the replace box: [yourcode]$1[yourcode]
Where [yourcode] is what you want to insert into the box.
So, if you want to make them all <li> then your replace box would be:
<li>$1</li>
Remember to use escape \ characters where they are needed, in case you need to insert restricted characters.
^ - beginning of a new line.
. - wildcard
* - any number of the previous character in the sequence (in this case a wildcard, so any text)
$ - the end of a line
() - denotes a block, it's how the $1 knows what text to put in it's place.
Sublime Text Search and Replace
Use search/replace on a text editor with regular expressions.
^ and $ represent the beginning and end of a line - thus allowing you to easily surround each line with the appropriate text.
Sometimes you can copy the newline character (as in copy the end of one line to the beginning of the next line), and replace that with whatever text you need.
You could always use the regular expression search / replace feature in Notepad++.

php/html: Force line breaks to appear inside textarea

This should not be that hard but I can't seem to find information on it. How do you get line breaks to appear inside a text area when you are echoing it from the server? In other words what is <some code> in line below?
<text area>first line <some code> second line <some code> third line</text area>
I know how to write out <some code>. I just need to know what it should be. I have tried \n, \r\n, '\n', "\n", \N and variations but cannot get the line breaks to display.
Note: This is not about displaying in HTML so <br> is not what I want. This is not about getting it to display if you are typing it yourself where you can type a carriage return, i.e. :
<textarea>first line
second line </textarea>
When you are outputting from server you cannot use keyboard. This is what code to accomplish above.
Thanks for any suggestions
This is a super old question, but I ran into the same issue ajaxing content into a text area.
Thanks to this answer I used the html code for a new line,
and that worked for me. So basically:
<textarea> Here's my returned text
And it gets two lines </textarea>
which (at least for me) comes out as
Here's my returned text
And it gets two lines
try this
<'p'>firstline<'/p'>
<'p'>secondline<'/p'>
remove comma from p and /p
for display \n in html you should use nl2br() php function .
otherwise you should using "\n" (not "/n") for break the line inside your text ;
You should try \r\n instead of /r/n.
You need to use "\r\n" (with double quotes) when echoing it out from PHP.

<Batch> How to find a line in file and add few lines under it?

I'm trying to find a line
"<!-- here comes the new post -->"
in an HTML file and add some lines that will contain some vars and special characters like <>#"" below it, without replacing the lines that are already below, because the line
will be always in the middle of the file.
--David
You should read Remove multi-line strings from a text file using a batch script.
If you can remove lines you should be also be able to insert lines.