Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

-4
votes
1answer
26 views

Unpack a shell archive (.shar file)

I have a shell script. How can i remove anything before # this line Everything before the # should be deleted. The script is too long to delete it manually. How can I do that automatically? ...
2
votes
1answer
25 views

If there are more than x number of pipes in a csv line, then delete the 2nd instance

I have a csv file which is supposed to contain 4 columns of data which include a product number, a title, a url and a price. Each column is separated by a | delimiter (this has to be maintained, there ...
1
vote
1answer
20 views

Perl script to split a file based on a pattern at a certain offset

I need your help to get an idea as to how to split a large file into small sub-files as said in the example below. Criteria is we are looking at offset 30 (31st bytes to 2 bytes). If the offset ...
2
votes
4answers
263 views

Output negative values, regardless of original sign, on selected lines

I am using the following code to read specific lines in an ASCII file "text.dat" sed -n '/Columnaxis/p' text.dat The output is Columnaxis: 100 In order to output only the second part previous ...
2
votes
1answer
47 views

Print multiple fields based on partial substring match inside one of the fields

From this data: "STRING1","c45621396a774a7a79b095a1b73b1d3b","2016-04-14T19:39:41.529978","1.0.4.4","7-sp1.0-amd64","","10.224.241.219|0.0.0.0|0.0.0.0|192.168.0.6|0.0.0.0" ...
-1
votes
1answer
33 views

Unix/Linux - File Formating

We have a source file which needs to be formatted into a fixed width file. Source File Format: Hdr1 Dtl1.1 Dtl1.2 Dtl1.3 Dtl1.4 Trailer0004 Hdr2 Dtl2.1 Dtl2.2 Dtl2.3 Dtl2.4 Dtl2.5 Trailer0005 . . . ...
4
votes
5answers
90 views

How do I sort on the first column every 4 lines in a file with a key in the second column

Example File : first column can have fixed set of 4 unordered values world1.com,world2.com,world3.com or world4.com second column is a key belongs to each line such that each of the four sets has ...
3
votes
1answer
27 views

Replace a word after matched word with incrementing values

I have a file like this - ! interface csa2549abA xxxx yyyy zzzz ! interface aso23apwoeAe aaa bbb ccc ! interface FastEthernet0/1 ppp qqq rrr ! and so ...
1
vote
1answer
24 views

Getting rid of a line with a perfect match (not substring) using sed

I want to delete a line which matches the word name but doesn't delete the lines have something following it. I can't seem to find an answer to this. I know sed -i '/name/d' * would delete the whole ...
3
votes
2answers
116 views

Filter text from each file and turn it into a list of comma-separated values

I'm trying to extract some information from multiple files and create a csv-type file. Until now I got the extracting and writing to file part working but don't know how I could add a comma between ...
3
votes
3answers
101 views

Reverse sequence of a file with POSIX tools?

Is there any clean, clear-cut POSIX equivalent to tac? Readability as well as succinctness should both be considered.
4
votes
4answers
166 views

Delete Nth line from each line matching a pattern

I have several files like file1, file2 ... etc in the same directory and each file may contain several lines matching PATTERN. I would like to delete the Nth line from each line matching PATTERN e.g. ...
4
votes
1answer
360 views

How do I sort words by syllable count?

How do I perform an ascending sort of a word list, based upon how many syllables each word contains? Example Input: something important dog cat bookshelf Example Output: dog cat something ...
0
votes
2answers
37 views

Carriage returns are prevent sed reading all my files

I have a long list of folders, inside every folder I have the file "log.dat". I wanted to read the value of a specific line inside this file. I saved the folders names in a file "All.txt", in the ...
1
vote
3answers
61 views

Delete the nth line from a matched string (which only occurs once in the file)

I have a question related to deletion of strings that appear at the n+2 position after the matched string which is at position n using awk for multiple files. I am able to print it using the command: ...
3
votes
2answers
54 views

Wrap and indent text using coreutils

Short version I would like to create a tabular display of multiline text, similar to the following: all Build all targets document Create documentation of source files in the subfolders ...
2
votes
3answers
71 views

Replace values in file

I have a files: $cat file1.txt 1234|W 1345|S 8427|D 2132|C 3243|V and my sql file is : $cat select.sql SELECT * FROM CUSTOMERS WHERE ID IN (FLAG); and I have a shell with the next ...
2
votes
1answer
33 views

Create table with frequency of unique names retrieved from multiple .csv files

I have 32 CSV files containing fetched information from a database. I need to make a frequency table in TSV/CSV format, where the names of the rows are the name of each file, and the names of the ...
0
votes
3answers
27 views

split lines and print it to new line for certain character

I need to split lines and print it to next line when pattern match. Like I have: ABC123xxx:: 2345 ABC345yyy:: 5678 ABC986zzz:: 7955 And I want it to print to new line when ABC pattern will come: ...
2
votes
2answers
71 views

How can I append a # in front of each line of a block of text?

This is part of my PHP Myadmin's configuration file: Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin <Directory /usr/share/phpMyAdmin/> AddDefaultCharset ...
-1
votes
4answers
46 views

How to filter the table names from .txt file [duplicate]

select * from emp; select * from dept; selection end; I want to obtain this output: select * from emp; select * from dept; I tried by using: awk '/select/{a=1} a; /;/{a=0}' ...
2
votes
2answers
86 views

pull out lines that contain 1 in 3rd column

I've got a text file with 633K lines all have 3 columns 768844 30050038638556 0 768892 30050018569904 1 768967 30050028970902 0 How do I pull out in a file those lines that have "1" in the ...
1
vote
3answers
42 views

Elegant way of counting how many times patterns from a file occur in another file

Imagine that we have two for example files. The first file is filled with unique names of employees created by combining the first two characters of the first name and the last 2 characters of the ...
1
vote
1answer
40 views

convert hexadecimal to binary

I have a text file with lines (each of 631 characters) consisting of 16 hexadecimal numbers 0,1,2,...,9,A,B,...,F. I would like to replace each number with the corresponding 4 bits of 0 and 1, i.e. 0 ...
-4
votes
3answers
52 views

I need a command to filter the statements from a .txt file

I have a file with the following contents: select * from emp; select * from dept; selection end; I want to obtain this output: select * from emp; select * from dept; I tried by ...
2
votes
2answers
67 views

Find (and strip) common initial whitespace from file/pipe

I am looking for a way to find and remove the common initial whitespace from a text stream or file. I do not want to remove all leading whitespace (that would be a simple sed 's/^[[:space:]]*//'). ...
0
votes
1answer
51 views

Only one line break in fasta file

I have a fasta file like: grep -A 7 -B 4 COSN229024 wrong.fasta: >COSN9627597 CGCTGGGCTCGCCTCCAGCCTGGCCTGCATTCCCAAATCTA >COSN8175610 CAAGAGAGAAATTCTGACACCTCCTAAGTCTACCAAGCTTT >COSN229024 ...
0
votes
2answers
32 views

Replacing string in HTML with value from lookup file

Situation: I have a source HTML file, with some values which must be completed with data from another file. Value that must be enriched is between a unique tag. ...
-4
votes
2answers
57 views

linux : find a lastname that has 5 characters only in a text

Name, lastname, phone number .This is the text : Hace, Apoio, 703-2101 Yoliot, Apostolos, 4222-1124 Jenny,Thano,105-4122 Heriom,Koun, 510-4122 Dekon, Atolo, 502-2522 Feow, R,685-3431 I ...
3
votes
1answer
72 views

Use awk as a stream editor

awk is the swiss army knife of text manipulation. If, however, I need to change small bits in a text, I reach out to sed generally. While it might be the best tool for the job, it is worth it to ...
2
votes
2answers
152 views

What's the fastest way to get n-th line of a text file [duplicate]

Given a file with m lines, how to get the n-th line. m can be smaller than n sometimes. I have tried: method1: sed -ne '10p' file.txt method2: sed -ne '10p' <file.txt method3: sed -ne '10{p;q;}' ...
-1
votes
1answer
41 views

How to delete a specific paragraph in text file?

I have this following html file. {% load staticfiles %} <html> <head> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> ...
0
votes
2answers
94 views

Why does `read` not pick up all my vars?

My apologies for the very basic question, but can someone please help explain why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done ...
-3
votes
1answer
46 views

Removing entire line with sed not working? [closed]

I have a line which looks like this: </File2>. I want to remove it using sed, but nothing I tried worked, I tried sed '/^<\/File2>$/d' so I thought maybe theres special characters at ...
1
vote
1answer
30 views

Join two files in a batch mode

I have many files with the following names: 0001mm.xyz , 0002mm.xyz , 0003mm.xyz ... 0001qm.xyz , 0002qm.xyz , 0003qm.xyz ... I want to join the contents of 0001mm.xyz and 0001qm.xyz ...
3
votes
4answers
59 views

Find matches on adjacent lines

I want to find adjacent matching lines, e.g., if the pattern matches are $ grep -n pattern file1 file2 file3 file1:10: ... file2:100: ... file2:1000: ... file2:1001: ... file3:1: ... file3:123: ... ...
2
votes
1answer
30 views

grep a range of unix timestamps from a logfile

I have a logfile where every log event has a unix timestamp: 1460332800 event a 1460332999 event b 1460342800 event c 1460417039 event d Is there a clever unix-style way to grep all log events ...
0
votes
1answer
33 views

Removing a pattern from a string and then storing the whole string into one index in an array

So I have a file of many fields which start with "Content:" like below... NOTE: The content goes over multiple lines Content:Wonderful time- even with the snow! What a great experience! From the ...
6
votes
3answers
77 views

sed/awk subscript numbers in chemical formulas using markup tags

I have hundreds of text files that include chemical formulas together with narrative including numerical values. The formulas are always preceded by white spaces but can be followed by white spaces, ...
1
vote
1answer
23 views

Appending a value to all columns

I have a "simple" question yet I have not found an answer to it nor have I gotten my code to work. I have a bunch of columns, and I want to append the average of the last column to ALL columns. For ...
1
vote
4answers
41 views

Bash file - find value from command output and keep as variable

I am trying to make a script that will conntect to a ups and get the battery value and store it in a variable. I have managed to connect to the ups and get infomation from it but I am strugling to ...
4
votes
1answer
75 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...
11
votes
7answers
914 views

Move first N lines of output to end without using temporary file

Imagine an output of a command like 44444 55555 11111 22222 33333 how can I yank the first N lines (first two in the example above) and append them at the end, but without using temp file (so only ...
3
votes
2answers
87 views

Search, insert, move and insert

I want to search each record (records are defined by blank lines) in a file for the pattern NAME#AAAA. If it matches, then insert an # in front of the record's AGE line and move that line to the top ...
1
vote
1answer
46 views

I want to search and replace a pattern

I want to search each record (records are defined by blank lines) in a file for the pattern NAME#AAAA. If it matches, then insert an # in front of the record's age and insert a line age NIL at the end ...
0
votes
1answer
24 views

How to assign variables associated with list of ranges to another table with integers

I have a list of integers from 1 to 6k, and I have a list of ranges (start/stop) with a third value I'd like to assign to each integer within those ranges. The list of ranges might look like this, ...
15
votes
12answers
894 views

Delete duplicate lines pairwise?

I encountered this use case today. It seems simple at first glance, but fiddling around with sort, uniq, sed and awk revealed that it's nontrivial. How can I delete all pairs of duplicate lines? In ...
1
vote
1answer
52 views

How to selectively remove columns and rows with bash?

I currently have a data set that looks like this: INPUT Hybridization REF TCGA-FA-8693-01A-11D-2399-05 TCGA-FA-8693-01A-11D-2399-05 TCGA-FA-8693-01A-11D-2399-05 ...
1
vote
1answer
34 views

Capture text between curly braces in C preprocessed file

I'm working with a preprocessed C source file. I want to extract one function for additional processing. I can find the start of the particular function with: gcc -DNDEBUG -march=native -E source.c ...
-3
votes
2answers
43 views

Extract a word from a line

Created a file employees: 1. Fred 2. Billy 1 3. Sally 1 4. Jim 2 5. Jane 2 6. Sue 3 7. Meg 3 Created a file “managers”: 1. Fred 2. Bill 3. Sally I want to print something like this: Fred ...