Tagged Questions
11
votes
2answers
665 views
echo a file without the first and last lines
Is there a simple way I can echo a file, skipping the first and last lines? I was looking at piping from head into tail, but for those it seems like I would have to know the total lines from the ...
2
votes
1answer
265 views
Regarding generating intersection and union of two csv files
I have two csv files, there are some overlap columns between these two files. Assume one file is called as A.csv and another is called as B.csv. The intersection of A and B is called as C.
I would ...
3
votes
1answer
337 views
How to do df only on root partition?
How can get df results only for / partition. The partition name/identification (/dev/sda2, /dev/cciss/c0d0p1) could vary on different computers.
3
votes
3answers
125 views
Regarding separate a single file into multiple files according to line separation
Currently, I have a plain text file, A, such as
lowest priority
very high significance.
outstanding
very novel
In this file, every line contains a sentence. I want to separate this file into ...
6
votes
4answers
206 views
extracting certain info from output
I'm trying to extract certain info from ffmpeg output.
Sample ffmpeg output:
configuration: --enable-memalign-hack --enable-mp3lame --enable-gpl --disable-vhook --disable-ffplay --disable-ffserver ...
0
votes
2answers
1k views
list the difference and overlap between two plain data set [duplicate]
Possible Duplicate:
Linux tools to treat files as sets and perform set operations on them
I have two data sets, A and B. The format for each data set is one number per line. For instance,
...
14
votes
5answers
1k views
Command line friendly spreadsheets
Does such a thing exist? Text-based spreadsheets that display well in a CLI environment. I'm aware that I could cat foobar.csvand do as I please, but it isn't particularly practical or attractive. I ...
1
vote
2answers
763 views
regex find and replace 0x0D, 0x0A characters
I have a text file of a database dump with some line break characters (0x0A0x0D) in the middle of lines. I want to replace them with commas, but I can't do it simply, because those characters are the ...
2
votes
2answers
2k views
extract middle section of lines of a text file?
I am writing a php script to parse a large text file do to database inserts from it. However on my host, the file is too large, and I hit the memory limit for php.
The file has about 16,000 lines; I ...
8
votes
2answers
1k views
How to replace all the tabs in each file in a file system branch with 2 spaces each?
I code Scala and it's convention is to use double spaces per level for identiation. But using different editors makes my sources filled with a mix of spaces and tabs.
I'd like to refactor all the ...
4
votes
3answers
2k views
How do I grep without leading whitespaces?
I'm greping through a large codebase, and leading whitespaces and tabulation seem to be quite annoying. Is there any way to get rid of it?
grep -R "something" ./
E.g, instead of:
foo/bar.cpp: ...
2
votes
1answer
195 views
rotating buffer type file logging utility
I'am trying to debug a server that throws a lot of logs on stdout/stderr. I need to redirect only last N lines to a file. Something like a rotating buffer feature there in tcpdump's -C & -W flags. ...
10
votes
2answers
488 views
Where has the trailing newline char gone from my command substitution?
The following code best describes the situation. Why is the last line not outputting the trailing newline char? Each line's output is shown in the comment. I'm using GNU bash, version 4.1.5
...
1
vote
3answers
359 views
Get line numbers for empty lines
I have a large pipe-delimited file where I need to find the line number of all lines where a certain field is empty.
I can use cut -d \| -f 6 filename.txt to output just that column.
What is a ...
21
votes
6answers
2k views
Linux tools to treat files as sets and perform set operations on them
Does anyone know of any linux tool specifically designed to treat files as sets and perform set operations on them? Like difference, intersection, etc?
2
votes
3answers
892 views
Printing unique lines
Is there some better solution for printing unique lines other than a combination of sort and uniq?
6
votes
1answer
246 views
Is there a way to make perl -i not clobber symlinks?
A friend of mine points out that if you do:
perl -pi.bak -e 's/foo/bar/' somefile
when "somefile" is actually a symlink, perl does just what the docs say it will do:
It does this by renaming ...
5
votes
3answers
1k views
command to layout tab separated list nicely
Sometimes, I'm getting as an input tab separated list, which is not quite aligned, for instance
var1 var2 var3
var_with_long_name_which_ruins_alignment var2 var3
Is there an easy way to render ...
13
votes
8answers
2k views
Is there a robust command line tool for processing csv files?
I work with CSV files and sometimes need to quickly check the contents of a row or column from the command line. In many cases cut, head, tail, and friends will do the job; however, cut cannot easily ...
11
votes
2answers
3k views
Filtering invalid utf8
I have a text file in an unknown or mixed encoding. I want to see the lines that contain a byte sequence that is not valid UTF-8 (by piping the text file into some program). Equivalently, I want to ...
4
votes
2answers
2k views
How do I insert a space every four characters in a long line?
I've got a long line that I want to insert a space every 4 characters, on a single lone line of solid text to make it easier to read, what's the simplest way to do this? also I should be able to input ...
12
votes
2answers
819 views
How can I count the number of different characters in a file?
I would need a program, that outputs the number of the different characters in a file. Example:
> stats testfile
' ': 207
'e': 186
'n': 102
Exists any tool, that do this?
5
votes
3answers
230 views
Searching a text file with a single line using regular expressions
as far as i know all unix text processing utilities are reading one line at a time and performing one action on this line.
I have a huge file with a single line of text which contains several tokens ...
24
votes
8answers
3k views
how do you sort du output by size?
How do you sort du -sh /dir/* by size? I read one site that said use | sort -n but that's obviously not right. Here's an example that is wrong.
[~]# du -sh /var/* | sort -n
0 /var/mail
1.2M ...
5
votes
2answers
634 views
sort output by column
I'd like to take this command find -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" | wc -l; done ( from here ). which has an output of basically
./kennel: 11062
...
2
votes
4answers
233 views
How can I manipulate the content of a file, by duplicating and changing some parts?
I want to manipulate a text-file. It contains many blocks of the form
CLASS
...some stuff ...
END
I want to duplicate each of these blocks and add and remove a line of it's content. Can I script ...
5
votes
4answers
209 views
How could I simplify this command to only use awk?
awk '/user/ {print $1 }' /etc/userdomains | sed 's/://'
the format of /etc/userdomains is
domain.tld: user
otherdomain.tld: otheruser
7
votes
2answers
359 views
How do I take a list and remove it from a file?
I have a long list of domain names that I need to remove from /etc/remotedomains. They're probably not in any particular order in the file. Each domain is on one line.
How could I iterate through the ...
6
votes
3answers
4k views
Grabbing the first [x] characters for a string from a pipe
If I have really long output from a command (single line) but I know I only want the first [x] (let's say 8) characters of the output, what's the easiest way to get that? There aren't any delimiters.
8
votes
5answers
389 views
What's the best way to take a segment out of a text file?
What's a good way of extracting say, lines 20 -45 out of a huge text file. Non-interactively of course!