Deleting blank lines to end of page - sed

I am trying to delete a file from the first blank line to the end of a .txt file. I am using the following line of code:
sed -i -b '/^$/,$d'
(taken almost directly from Unix Power Tools). In a multi-page document, this successfully deletes the second page of text, but still leaves the footer on the first page(see below *text slightly modified for space):
29 0235600 Drain Pan
62 6151060 Nut, Serrated 5/16-18 Hex
7003932
30 6201920 Screw, 8-15X2 6-Lobe PH
W/H Network Svce
63
64 7003931 W/H Network Svce
4
# 1 - Revision D - February, 2007
375844
Previous Page Main Menu Model 648PRO Menu Next Page
I am using GNU sed version 4.2.1
Any suggestions please.

Those things at the end (CR/LF) are DOS style end-of-line characters. I don't know why the -b option isn't coping with them, but you can try this kludge:
sed -i '/^.$/,$d'

Related

How to go to a specific character offset

I'm on MacOS 10.15.7, using BBedit 13.5.5. Under "Go ->" There is only Go to Line Number. I want to go to character 145 of the file.
Here's a crib from page 103 of the user manual (you'll find it on the Help menu):
Alternatively, you can jump to an absolute character offset, by using the ‘line:column’ syntax but leaving the ‘line’ blank or specifying it as zero. For example, entering “0:1500” or “:1500” will cause BBEdit to place the insertion point before the 1500th character in the document. (The range syntax works too; so you could use “0:12-0:56” to select characters 12 through 56.)
Correct - if you select Go from the menu, it says, after selecting Line Number:
:C character offset C in document
So, :20 goes to position 20. But, I have found it is off a few characters, perhaps it is not counting line feed.

What are the supported editing commands for the GNU APL line editor (∇-editor)?

The GNU APL documentation on the line editor seems to assume one already knows how to use it. I only see mention of what commands/syntax '... are not fully supported in GNU APL'.
Compare with the documentation of Dyalog's APL ∇-editor, or MicroAPL.
I'd be willing to prepare a patch to submit for the documentation if anyone has a reference.
The main developer of GNU APL, Jürgen Sauermann, has told me that GNU APL's editor is a clone of APL2's line editor, and thus should support the same commands:
command
action
[⎕]
display the current whole definition
[⎕2 7 1 …]
display specific lines
[⎕2-7]
display a range of lines
[⎕-7]
display all lines until a specific line
[⎕7-]
display all lines beginning with a specific line
[7] code
replace a specific line
[2.1] code
insert a line between two lines
[∆2 7 1]
delete specific lines
[∆2-7]
delete a range of lines
[∆-7]
delete all lines until a specific line
[∆7-]
delete all lines beginning with a specific line
[→]
quit without saving
[2⎕7]
display line 2 for editing, placing the cursor at position 7
[2⎕0]
display line 2 for editing, placing the cursor at the end of the line
Source: IBM's APL2 Language Reference
See:
APL: The Language and Its Usage;
Polivka & Pakin;
1975

Atom / Github removing end-of-file newline

Using Atom 1.14.3, I have whitespace package that handles auto-inserting newlines at the end of files.
Even if I delete the end newline and hit save, it re-adds the newline. This is good.
Whitespace package configuration seems to be okay:
The problem is, when I commit to Github, it says the newline has been removed:
Why is this? Is it an Atom issue, or a potential local github setting issue?
EDIT: somehow, I needed to disable whitespace package, manually add two CRLF at the end of the file, and then commit for Github to pick up the single CRLF at the end of the file.
I think you might be misunderstanding where the newlines are.
Let's look at your two screenshots, and where the newlines are in each.
233 return router;\n
234 };\n
Here we have 234 as the last line in the file. We have a line 235 displayed, but that is because the newline on 234 creates the next line for your editor cursor to be on. If you started typing on 235, you'd be creating more content. But right now, 235 is an empty line (including having no terminating newline).
233 return router;\n
234 };\n
235 \n
This is similar except it also has an empty line 235 that ends with a newline. Now the newline-less empty input line has moved to 236.
When you saved with the whitespace package active, it removed extraneous newlines at the end of the file, leaving only one. As in the first screenshot. However, when you look at the Github diff, things are little different. Github is showing you the file contents, not in an editor. So there is no reason to have the phantom last line for your cursor. Instead, it shows you the simple truth of the matter: line 234 is the last line in the file. Line 235 is now gone.
Let's take a look at the settings for the whitespace package. Specifically the first setting:
Ensure Single Trailing Newline
If the buffer doesn't end with a newline character when it's saved, then append one. If it ends with more than one newline, remove all but one. To disable/enable for a certain language, use syntax-scoped properties in your config.cson.
Here are the first two sentences of the description again, with some emphasis added:
If the buffer doesn't end with a newline character when it's saved, then append one. If it ends with more than one newline, remove all but one.

Merging two files in Notepad

Hi i have two long files both 30k lines long. Is there any way of merging them like that in Notepad++ or using other software?
1st line from 1st file: 1st line from second file
If you happen to have python on your computer, using itertools you can merge both files. Keep in mind that if one file ends before the other, whichever file keeps going will continue to put their lines into the output file.
from itertoools import izip
with open("outputfile.txt", 'w') as output:
with open ("firstfile.txt") as f1 , with open ("secondfile.txt") as f2:
for file1,file2 in zip(f1,f2):
output.write(f1)
output.write(f2)
For decades there have existed a command to do exactly this, paste. Example:
$ cat > file1
one
two
three
$ cat > file2
1
2
3
$ paste file1 file2
one 1
two 2
three 3
$
The free gnu version is currently part of coreutils, which I think is simplest to install via cygwin. If you need the separator to be exactly colon+space you can just pipe paste's output through sed 's/\t/: /'.
Here is a possible solution using Excel:
1.)
Open the first file with Excel (all the text should be in one column)
2.)
Open the second file with Excel (all the text should be in one column)
3.)
Go back to your first file and add a : to every row of the second column
4.)
Copy the first column of the second file and paste it to the third row of the first file
5.)
Save the combined file as *.txt file
this is not possible in Notepad as far as i know, so your best bet is Notepad++. is there a reason why you don't wanna use Notepad++?
EDIT: I see, i deserve that -rep :P sorry for not reading correctly.
What you do in Notepad++ is:
1. open Notepad++ and navigate to Plugins > Plugin Manager > Show Plugin Manager
2. look for and Check "Compare"
3. click "Install"
now what you do is you open your first file in Notepad++. after that, you open your second files inside the same window of Notepad++ and drag the second file to the middle of Notepad++ (so click and drag the second document to the middle of Notepad++) once you release, it will ask you what to do. Click on "Move next to eachother"
after you have done that, you can now click Plugin > Compare > Compare. this will comapre the 2 files and give you exactly whats different between them.
Sorry for putting the answer quickly without reading more carefully.

Number of spaces in Tab - OpenEdge

In OpenEdge the tab can be configured to any number of spaces, usually is configured to 4 spaces.
To insert a tab in a text can be used: ~t.
What I want to find is how many spaces have the tab set.
For example, I am reading a file line by line, and for each line I want to see how many spaces are at the beginning.
I am using:
iNoOfBeginningSpaces = index (cLine, left-trim (cLine)) - 1.
But if the line begins with 3 tabs then it gives me 3, and not the number of the spaces: 3 * spaces from tab.
Is there a way to find the number of beginning spaces of a line, treating the tab as x numbers of spaces?
No. Spaces and tabs are not the same thing. You are getting confused by the fact that programming editors, word processors and printers convert tabs to spaces to get to tab stops. But in a data file no such conversion occurs (unless you are saving the file from an editor that does such conversions).
I will tell you how to check in your AppBuilder.
On the AppBuilder Menu you go to OPTIONS and then EDITING OPTIONS and there you can set how much "spaces" the editor uses for Tabs and Syntax indents. But this is basically for DISPLAY purposes within APPBUILDER.
Tom has given you the correct technical answer, a tab is a type of control character that can be interpreted differently by different apps. It has a different value than spaces.Below you can see the value of space and Horizontal Tab.
Char Oct Dec Hex Control-Key Control Action
HT 11 9 9 ^I Horizontal tab, move to next tab stop
=============================================
Char Octal Dec Hex Description
SP 40 32 20 Space