unix-utils

Easy Way to Split a Large Text File?

I've got a large (by number of lines) plain text file that I'd like to split into smaller files, also by number of lines. So if my file has around 2M lines, I'd like to split it up into 10 files that contain 200k lines, or 100 files that contain 20k lines (plus one file with the remainder; being evenly divisible doesn't matter). I coul...

turning text into paginated two-column format and pipe this into less

I want to read a long text file in two-column format on my terminal. This means that the columns must be page-aware, so that text at the bottom of the first column continues at the top of the second column, but text at the bottom of the second column continues at the beginning of the first column after a page-down. I tried column and l...

LESSCHARSET=utf-8 less doesn't seem to work

I'm trying to view a UTF-8 text file/stream in less, and even if I invoke it like this: cat file | LESSCHARSET=utf-8 less the non-ASCII compatible UTF-8 characters don't display correctly. Instead, their hex values appear highlighted in brackets, e.g. <F4>. The reading the same text in vim with UTF-8 encoding poses no problems. So I'...

How important is adding quiet/verbose flags to new unix tools?

I'm writing some unix-style Ruby scripts that take option flags. Normally, I write a lot of STDOUT.puts and STDERR.puts statments in these scripts. Now I'm wondering whether it's "good form" to put in --verbose or -q flags for switching on or off helpful output to STDERR. Two arguments against doing that are that it would make the p...

how do you script gnu screen from within a screen session to open new windows and run commands in them?

From within a screen session, I'd like to run a shell script that opens a few new screen windows in the same session and start running some programs in them. I need a script like this: screen -t newWindow [switch to newWindow and execute a command] screen -t newWindow2 [switch to newWindow2 and execute a command] I don't know how to ...

When using vim or less in gnu screen, quitting vim or less leaves a lingering imprint

On my new Ubuntu system, I start a screen session and edit a file in vim or view it in less. After I quit, the screen doesn't redraw itself, but simply scrolls up to show a command line under all the stuff I was just viewing in vim or less. How can I change this so that quitting vim will return me to the screen the way it was before I ...

How to find out how namespace got polluted?

Consider the following little piece of code: // all of these include other headers, lots of code: #include "myheader1.h" #include "myheader2.h" #include <string> void foo() { string s("hello world"); // oh no, why does this compile?? } This compiles, so obviously some of the recursively included header files has a using namespace...

Merge two files using cygwin tools

I have one tab separated file (file1.txt) with two columns and one file (file2.txt) with a long string of text. I want to replace specific characters in file2 with the column values in file1. An example: file1.txt text1 text11 text2 text22 text3 text33 file2.txt I want to insert text here:$1 and the other text here: $2 The desire...

Flashing window in gnu screen

I really like gnu screen but there is a problem in my environment when I use it. Examle: username@domain:/var/www$ l Display all 130 possibilities? (y or n) when you click [Tab] to perform autocompletion there is a screen flashing for a very short period of time(looks like white screen but I can see it for a very-very short time). T...

gnu screen: reattach all previously detached sessions

I have a few windows in a single screen session and then I want to detach my session. There is no problem with that. But I can't find a way to restore all windows within my previously detached session. I can see that I can restore just one of them by ID. But how can I reattach exact the same session environment with all the windows in ...

Sorted directory size display in Unix

How do i display directory sizes in a sorted manner in Unix while listing only innermost sub-directories? For example, I don't want get to something like this - 100270480 /a/b/BP/b/bat/qc3 100270416 /a/b/BP/b/bat/qc3/logs 99020464 /a/b/BP/b/bat/qc3/logs/i 99005456 /a/b/BP/b/bat/qc5 99005408 /a...

Extracting character range form longline with sed or awk or grep?

So i have a 1 long line with characters, for example numbers[1-1024] in one line(no "\n", "\t" and "\b"): 1 2 3 4 5 6 7 8 9 10 11 ... 1024 How do i extract and print characters for example exactly 55 characters after 46? So output would be: 47 48 49 ... 101 Thanks. ...

Unix uniq utility: What is wrong with this code?

What I want to accomplish: print duplicated lines This is what uniq man says: SYNOPSIS uniq [OPTION]... [INPUT [OUTPUT]] DESCRIPTION Discard all but one of successive identical lines from INPUT (or stan- dard input), writing to OUTPUT (or standard output). ... -d, --repeated only print duplicate lines This is what I try to exe...

Translate a Unix1Liner to PowerShell

I would like to translate the following Unix 1 Liner to PowerShell. Synopsis of the command: This command will search recursively form the PWD (pressent working directory) for any file with the extenstion .jsp, and look inside the file for a simple string match of 'logoutButtonForm'. If it finds a match, it will print the file name and...

Is there a way to have a string as a switch using getopts?

I am seeing if there is a way for getopts to handle switches with strings instead of characters. For example, I would like to supply something like this: script.ksh -file1 file1.txt -file2.txt Instead of: script.ksh -f file1.txt -g file2.txt Is this possible with unix getopts? Thanks! ...

UNIX - Renaming files with long names

I am screwed. I misused wildcards like a moron, in the rename command. I repeated names twice in a 3gig folder, which I cannot afford to delete. Now, the rename command is not working, and it says the file name is too long. Please help me. If programming can solve this, please let me know. I am a competent programmer in Java and PHP....

Extracting n rows of text from a large csv file

I have a CSV file (foo.csv) with 200,000 rows. I need to break it into four files (foo1.csv, foo2.csv... etc.) with 50,000 rows each. I already tried simple ctrl-v/-c using gui text editors, but the my computer slows to a halt. What unix command(s) could I use to accomplish this task? ...

UNIX shell: how do you tail up to a searchable expression?

The end of git status looks like this: # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Classes/Default.png # Classes/[email protected] ... Since you might have any number of untracked files, I'm trying to tail from the end of the file to "Untracked files" and save it to a temp file, s...

Turn off colors in Netware console?

I'm looking for a method of changing colors in default Novell Netware (OES) console ...