Manipulation of text by programs, scripts, etc.
3
votes
2answers
4k views
How do I delete the first n lines of an ascii file using shell commands?
I have multiple files that contain ascii text information in the first 5-10 lines, followed by well-tabulated matrix information. In a shell script, I want to remove these first few lines of text so ...
3
votes
1answer
301 views
How to display TSV (csv) in console, when empty cells are missed by: `column -t -s $'\t' `
I have file with columns spearated with tab.
I have file when some rows have empty cells (on begining, in middle).
In such cases column -t -s $'\t' simply fails:
Input:
$ echo -e ...
3
votes
2answers
994 views
My awk program to change spaces into tabs doesn't work
How to write a shell script which uses awk to read in the data file students.txt and output the data in the tabbed format as shown:
Surname Forename MSc Stream Date of Birth
Smith John IT 15.01.1986
...
3
votes
1answer
1k views
How to numerical sort by last column?
I have this input:
sdkxyosl 1
safkls 2
asdf--asdfasxy_asd 5
dkd8k jasd 29
sdi44sw 43
asasd afsdfs 10
rklyasd 4
I need this output:
sdi44sw 43
dkd8k jasd 29
asasd afsdfs 10
asdf--asdfasxy_asd 5
...
3
votes
3answers
2k views
Is it possible in bash, to start reading a file from an arbitary byte count offset?
I want to locate a date which is somewhere in an 8 GB log (text).
Can I somewhat bypass a full sequential read, and first do binary splits of the file (size), or somehow navigating the filesystem ...
3
votes
1answer
687 views
How does one find and replace text in all open files with geany?
How does one find and replace text in all open files with geany?
2
votes
3answers
2k views
How to search and replace text in all php-files in a directory and it's subdirectories
I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern.
The search pattern is quite long ( > 5000 ...
2
votes
1answer
240 views
How does one find and replace text in all open files with LibreOffice?
How does one find and replace text in all open files with LibreOffice?
1
vote
1answer
198 views
Verify that /etc/passwd has correct number of fields on each line?
I'm looking for an easy, portable way to validate the number of fields in /etc/passwd, /etc/shadow, /etc/group and /etc/master.passwd. This would run on FreeBSD, Linux and other Un*xes. pwck does ...
1
vote
3answers
312 views
Switch from grep to sed
I have a files students.txt, with lines of the form:
Surname, Forename: Day.Month.Year: Degree
For example:
Smith, John: 15.01.1986: MSc IT
Taylor, Susan: 04.05.1987: MSc IT
Thomas, Steve: ...
7
votes
1answer
236 views
Change date “July 29th, 2011” to “20110729”
I have lots of HTML files contains date with format July 29th, 2011
I want to change date format July 29th, 2011 to 20110729, December 9th, 2010 to 20101209, etc.
I think sed may works but still ...
7
votes
2answers
775 views
How can I cut a large file in place?
I have a very big text file, about 80GB, and I need to cut a part form it that lies between two given lines. The part I need is not big, and I have not enough space left on the hard drive to do things ...
7
votes
2answers
402 views
What governs the limits of shell brace expansion?
In this example I refer to the expansion of a sequence of integers, but perhaps(?) the limits would be relevant to all aspects of brace expansion.. This more general view is also of interest to me.
...
7
votes
2answers
118 views
How does one find and replace text in all open files with jed?
How does one find and replace text in all open files with jed?
6
votes
4answers
12k views
Finding text between two specific characters or strings
Say I have lines like this:
*[234]*
*[23]*
*[1453]*
where * represents any string (except a string of the form [number]). How can I parse these lines with a command line utility and extract the ...
5
votes
2answers
201 views
Find all files with a Python Shebang
I'm trying to run a PEP8 check against a large source tree. The tree is comprised of a mix of files in various languages. The idea is to check all the Python scripts without having to explicitly list ...
5
votes
4answers
249 views
Tool to create text files from a template
I have to regularly create 100+ text files from templates.
I currently use an overly complicated shell script. I think there is a smarter way to handle this, but I don't know how.
I have a "database" ...
5
votes
2answers
104 views
Sort fields inline
I'm trying to sort within a line of input over an unknown number of fields:
Input:
ab bc
bc ab
cd ef bc
bc cd ef
cd bc ab
ef ab bc cd gh
Output:
ab bc
ab bc
bc cd ef
bc cd ef
ab cb cd
ab bc cd ...
4
votes
3answers
576 views
Any (text based) plotting tools in unix toolbox?
I was wondering if there are any generic plotting tools available in the unix toolbox?
By plotting I mean simple bars or things you see in many curses based utilities.
And by unix toolbox I mean ...
3
votes
1answer
185 views
grep list of names and information from bigger file
I have two files: one with list of names (500 entries) and other having some more information for each entry in A.txt and extra entries too.
File A.txt (each line is starting with > (fasta format) ...
3
votes
2answers
339 views
How to count the number of lines in a UTF-16LE/CR-LF/BOM file?
The immediate thought is wc, but then the next not-so-immediate thought is... Is *nix's wc purely for *nix line endings \x0a?... It seems so.
I've semi-wangled my way around it, but I feel there ...
3
votes
2answers
286 views
How to skip file in sed if it contains regex?
I currently use the following simplified command to remove trailing whitespace and add a newline at end of file where needed:
find . -type f -exec sed -i -e 's/[ \t]\+\(\r\?\)$/\1/;$a\' {} \+
As ...
3
votes
5answers
604 views
How to replace a list of placeholders in a text file?
I have a text (configuration) file, but the program that reads the file unfortunately doesn't allow using any kind of variables. So I'd like to use a preprocessor that replaces a set of placeholders ...
2
votes
3answers
61 views
Scripting to domain allocation to server
I have two text files:
file #1: domain.txt
cocacola.com
airtel.com
pepsi.com
file #2: servers.txt
192.0.53.42 , 4 # 4 domains already allocated on server 192.0.53.42
192.53.1.2 , 1 # 1 ...
2
votes
5answers
2k views
Bash iterate over a list of strings
I have this bash script:
for opt in string1 string2 string3 ... string99
do somestuff
It works, but I would like to replace the explicit listing of my strings with a file which actually contains ...
2
votes
1answer
936 views
Delete last character in a word but only if the character is there - in bash
How to remove last character only if it's there?
input:
OpenOffice.org/m
openOffice.org/ozm
Pers.
Pfg.
phil.
Prof.
resp.
Roonstr./m
roonstr./ozm
desired output:
OpenOffice.org
openOffice.org
...
2
votes
1answer
205 views
How to join vCards lines
vCard uses a special way to split long lines: At 75 characters, insert a DOS newline and a space. Joining therefore means to replace all occurrences of the sequence "CR, LF, space" with an empty ...
2
votes
4answers
2k views
Print odd-numbered lines, print even-numbered lines
I want to print the odd-numbered and even-numbered lines from files.
I found this shell script which makes use of echo.
#!/bin/bash
# Write a shell script that, given a file name as the argument ...
2
votes
3answers
251 views
Returning only the portion of a line after a matching pattern
I have a file (file_name) which contains exactly one occurance of the string Result:, at the start of a line. I want to print all the characters after the string Result: in that line until I encounter ...
2
votes
1answer
191 views
Possible to extract title and pagenum of each page in a pdf file
I was wondering if there are some ways to extract title and pagenum of each page in a pdf file? Either by some applications, or by programming in some programming language with some pdf libraries?
...
2
votes
1answer
194 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. ...
2
votes
2answers
2k views
How does one find and replace text in all open files with kate?
How does one find and replace text in all open files with kate?
2
votes
2answers
516 views
How does one find and replace text in all open files with gedit?
How does one find and replace text in all open files with gedit?
1
vote
1answer
341 views
Reading the contents of the file and splitting using ksh
We're using a ksh script for installing one product.
I've another config file, I'd need to read this configuration file from my main script
Content of the Configuration file:
...
1
vote
1answer
236 views
Reading two files into an IFS while loop — Is there a way to get a zero diff result in this case?
I have a text file full of several hundred lines of sequences like this:
b 29.
b 52.
c 84.
c 83.
c 94.
c 93.
c 61.
b 38.
c 81.
c 92.
c 28.
c 37.
...
