Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

0
votes
0answers
4 views

Replace a word after matched word with incrementing values

I have a file like this - ! interface csa2549abA xxxx yyyy zzzz ! interface asoieAPO123 aaa bbb ccc ! and so on. What I want is to rename the interfaces to ...
1
vote
2answers
15 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
3answers
99 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.
17
votes
9answers
13k views

How can I print lines from file backwards (without using “tac”)?

I want to print lines from a file backwards without using tac command. Is there any other solution to do such thing with bash?
3
votes
2answers
106 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 ...
4
votes
4answers
158 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. ...
3
votes
2answers
51 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 ...
4
votes
1answer
349 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
35 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 ...
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 ...
1
vote
3answers
56 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: ...
8
votes
6answers
12k views

How to grep for text in a file and display the paragraph that has the text?

Below is the text in the file: Pseudo name=Apple Code=42B state=fault Pseudo name=Prance Code=43B state=good I need to grep for "42B" and get the output from the above text like: Pseudo ...
2
votes
3answers
67 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 ...
34
votes
9answers
9k views

Is there a way to modify a file in-place?

I have a fairly large file (35Gb), and I would like to filter this file in situ (i.e. I don't have enough disk space for another file), specifically I want to grep and ignore some patterns — is there ...
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
3answers
386 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
-4
votes
3answers
50 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 ...
3
votes
7answers
301 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
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. ...
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
45 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 ...
2
votes
2answers
64 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:]]*//'). ...
7
votes
6answers
3k views

How to grep-inverse-match and exclude “before” and “after” lines

Consider a text file with the following entries: aaa bbb ccc ddd eee fff ggg hhh iii Given a pattern (e.g. fff), I would like to grep the file above to get in the output: all_lines except ...
2
votes
4answers
4k views

Error: ambiguous redirect while transferring output to command

Output to redirect in script: 511@ubuntu:~/Unix/test$ ls -ltr |awk '{print $9}' default.txt dfah.txt fruit.txt fruit_prices.txt dfh.txt header.txt testfile.txt topoutput.txt Script written on shell ...
1
vote
1answer
39 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 ...
1
vote
3answers
41 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 ...
0
votes
1answer
50 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
1answer
82 views

seeking hints for correct escaping of sed commands WITHIN yaml

I am having a hard time finding the issue why following lines of "code" break my cloud-init config. Basically I am calling a son object as part of the DigitalOcean API which has a YAML format - I got ...
2
votes
3answers
620 views

Text to yaml conversion

I have a tab separated text file in this format: your-email your-order-id PayPal-transaction-id your-first-name your-second-name s@ess.com 12345 54321 sooky spooky t@tee.com 23456 ...
24
votes
7answers
29k views

how do I trim each line in bash?

I would like to remove all leading and trailing spaces and tabs from each line in an output. Is there a simple tool like trim I could pipe my output into?
-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
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: ... ...
3
votes
1answer
71 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;}' ...
4
votes
4answers
193 views

printing a block of text that matches a pattern

Using just shell script, how to search a text file and list all whole blocks of lines that has inside some text (simple grep criteria). The text file has blocks of lines separated by ...
-1
votes
1answer
75 views

How can I print a specific occurrence of a range pattern?

I am trying to extract several data fields out of somewhat peculiarly formatted strings. Each string has a format similar to the following (spaces added for emphasis): 1 abcd 2 1 efg 2 hij 3 ...
-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 ...
0
votes
2answers
60 views

format command output with variable and fixed space

How can I achieve this best maintaining the hierarchy on the left and aligning the size value on the right? Also, at the same time I'd like to round the size to one or two digits. I tried with printf ...
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 ...
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, ...
3
votes
1answer
127 views

Replace with sed until match in a line

I have to replace all "." characters before the "=" character in every line in a file. The lines are like this: one.two.three=something four.five=1 six.seven=127.0.0.1 ...
84
votes
5answers
68k views

Can grep output only specified groupings that match?

Say I have a file: # file: 'test.txt' foobar bash 1 bash foobar happy foobar I only want to know what words appear after "foobar", so I can use this regex: "foobar \(\w\+\)" The parenthesis ...
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 ...
11
votes
7answers
877 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 ...
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 ...