sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

-1
votes
2answers
75 views

Printing all lines of a file with multiple columns in shell script

I have a file with 4 columns with the below format name;user_id;dob;date_of_joining I want to print all the variables in below output via shell script The employee "$name" is having "$user_id" ...
2
votes
2answers
52 views

Extract content between tags

I have a file with data as below I want to extract the lines and write to another files. The o/p should be I want to do this in a unix shell script.Can someone hellp me on this. I know this can be ...
1
vote
4answers
55 views

Add a space or tab before the last character in each line

I have a file with a list of values that end with a letter. Is there an easy way to add a space or tab before the last character of each line to separate the number from the letter? 44A 354T ...
12
votes
6answers
2k views

How to delete the last column of a file in Linux

I want to delete the last column of a txt file, while I do not know what the column number is. How could I do this? Example: Input: 1223 1234 1323 ... 2222 123 1233 1234 1233 ... 3444 125 0000 5553 ...
3
votes
3answers
85 views

How do I create uniform columns from text containing both tabs and spaces?

In the simplest form, let's say I have an auto-generated file called file.txt. The contents of file.txt appears as follows: Source Destination Maximum To Maximum ...
1
vote
2answers
48 views

How do I stream edit progress-like output?

I'm having trouble editing some progress output. In this case it's Postgres' pg_basebackup, but it's similar to other progress output like curl and wget. Take for example the output of this: ...
0
votes
3answers
33 views

how to add a row name column into a file in linux?

I Have a huge file (50000 rows) looks like : input.txt: 123315334262625363534 265343426272282827262 224343536625242536363 635352627273635373732 363353533637383838327 635342422325337474524 I want ...
1
vote
3answers
182 views

Help with awk / sed shell script

I have to make a script using the info in the following table (fake info) AnimalNumber,DOB,Gender,Breed,Date-moved-in IE161289240602,04/02/2010,M,AAX,20/07/2011, ...
6
votes
5answers
291 views

Find 2nd Occurrence of string from the end of file

I have a log file that looks like this, Another thousand lines above this I 10/03/15 12:04AM 42 [Important] 4th to last I 10/03/15 04:31AM 42 (534642712) [1974,2106,258605080,0,0,32817,30711] I ...
2
votes
1answer
106 views

How can I append an incremental count to every line of a text file?

I have a large document with over 500000 lines like this car milk dog And I want to count every line and add the number in the end of line and the final document to look like this car1 milk1 dog1 ...
1
vote
4answers
85 views

Find the smallest numbers in the second column corresponding to index values in first column

I have some very large tables and I need to extract specific rows. I am illustrating the task using a simple example. Say, I have weighed a number of apples, bananas and oranges. I need to extract the ...
0
votes
2answers
82 views

Quick way to delete a line from an extremely large file [duplicate]

I have a 67GB .csv file (I know... I know...) I need to remove the 4,125,878th line from the file as it is corrupt. My CSV parsing tools won't ignore or skip it. I could use sed to do something ...
0
votes
1answer
38 views

how to extract some rows in a data file by comparing with another data file? (merging) [duplicate]

I have 2 different file : first file: id1 19501112 id2 19831207 1d4 20001212 id6 20000101 id10 20061213 id11 20081212 id12 20100109 id13 20101218 id14 20101212 id15 20111111 id16 20150919 id20 ...
4
votes
5answers
421 views

How to split a file based on information within a column in linux

I would like to separate those rows where the value in second column is smaller than a specific value. example input: id1 19501112 id2 19831207 id3 20001212 id6 20000101 id10 20061213 id11 20081212 ...
1
vote
2answers
54 views

How to make + work in sed's regexps on FreeBSD?

Consider the following typescript: $ freebsd-version 10.0-RELEASE-p5 $ echo ' found' | sed -n '/[[:blank:]]\+/p' $ echo ' found' | grep '[[:blank:]]\+' found When I do this on Arch Linux with GNU ...
0
votes
1answer
32 views

Increase a number using ssh

Suppose 3 hosts called host1 ,host2, host3 I want to replace the string 5801 on file /etc/FAKEFILE using +1 for every host,with sed(but perl,awk also ok) using ssh. Must return 5802 on host1 5803 on ...
1
vote
2answers
30 views

extract part of the text from all matching lines

I am running a for loop against set of servers to find the cert expiry. Output of the cert command will be below for each server: line 1 line 2 line 3 Valid From: Tuesday, 29 September 2015 10:40:13 ...
1
vote
2answers
22 views

Duplication of each line while changing some value within each copy of a line differently in linux

I Would like to have each line in a file repeated a two number of times while in in first copy of line any value of 3 be changed into 2 and any value of 4 be changed into 1, and in second copy of each ...
2
votes
4answers
148 views

Grepping pieces of a string to form a new string

I am parsing some log files and have grepped out the errors. Each line looks something like this: CreateOrder_hostname1.domain.com_201509291530_tee.log:2015-09-29 15:42:06,715:ERROR ...
18
votes
1answer
1k views

How does the command sed '1!G;h;$!d' reverse the contents of a file?

My question is related to the sed-specific solution given in this answer for this question of reverse grepping. The sed/grep solution that I am unable to decipher is the following one: sed ...
0
votes
2answers
55 views

select and move the contents to another file

I have a file with the below contents. All I need to do is filter the ALTER script that has UNIQUE keyword in it and move it to a different file. I tried using sed -n '/ALTER TABLE/,/UNIQUE("ID");/p' ...
2
votes
2answers
63 views

Cleaning PHP exploits from infected files using sed

Recently my server has been a target for a series php exploit attacks and using ClamAV I was able to identify many infected files. The catch here is that there are legitimate files that are infected ...
0
votes
0answers
24 views

How to restore sbatch array job output file names to their original names

In order to submit array jobs using Slurm, I've renamed hundreds of files with incremental numbers using the following command: COUNT=1 for file in ./*; do mv "$file" "${COUNT}" let COUNT++ ...
1
vote
2answers
100 views

Find and replace a string if particular pattern is found in a line

All I need to do is, search for CCSID in this file, wherever it finds CCSID, the CHAR in that line should be replaced with NCHAR and VARCHAR in that line should be replaced with NVARCHAR2. I tried ...
2
votes
2answers
58 views

Exchanging One Column From File1 with files from File2

I have two files. The first file has 11 columns, for example: 1 2 3 4 5 6 7 8 9 10 11 The second has 10 columns and might look like this: 11 22 33 44 55 66 77 88 99 100 What I want to do is look ...
0
votes
1answer
103 views

How to delete the lines that starts with a specific word and end with a specific word

Eg: CREATE TABLE COMM.ACL_ENTRY ( ACL_OID CHAR(18) FOR BIT DATA NOT NULL , USER_DESC_TYPE FOR COLUMN USER_00001 BIGINT NOT NULL , USER_DESC_OID FOR COLUMN USER_00002 ...
0
votes
2answers
55 views

sed search and replace problem

I am trying to replace a string from a file which contains '&' in its value. vari = '111|abc & efg|123' varj = '222|abc & efg|123' echo $vari | sed -e "s/$vari/$varj/g" output is ...
3
votes
2answers
152 views

Delete till first occurrence of colon using sed

My sed command is, sed '/(.*:)/d' <<< 'abcd:bcde:cdeaf' It must return, bcde:cdeaf (i.e.) all characters before the first colon in the line and the colon itself must be removed. But ...
1
vote
1answer
78 views

Ignore full lines with sed

I've searched high and low across the internet, but I can't seem to find an answer that satisfies this question - I need to use sed to display all lines in a file, excluding a group of them. I'm not ...
0
votes
1answer
164 views

How do I find block of text, from a text file, containing a specific string [duplicate]

I've been looking to extract a block of text, from a text file, containing a string with no success. Any help would be really appreciated. For example: I have a file named xyz with below contents: ...
1
vote
2answers
56 views

sed - how to print text block from the second pattern?

I have an html page that contains two tables. Both tables begin with the same tag "<table role="grid">" and I want to display the second table code. For now, I know only display the first ...
0
votes
1answer
67 views

sed html parsing

I have to parse HTML to change text between two brackets that are not HTML code back to &lt; or &gt;. Here an example of my HTML code that I have to replace: ...
1
vote
2answers
69 views

how to swap text inside files [duplicate]

Inside my file I need to swap places of all instances of : grep 'search string' and sed '/string of text/,/string of text/{//!d}' In VI I have tried a regex with no luck - it says something ...
3
votes
4answers
335 views

How do I remove first character in specific column using sed

I have file with the next structure: 999963803|081439403|FFF|33 999964211|081823904|FFF|33 999970948|081765738|FFF|33 999971835|081736346|FFF|33 999972780|082127527|FFF|33 I need remove the first ...
0
votes
1answer
18 views

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME.

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
0
votes
3answers
57 views

Null value than rename file

I have a shell to a task but I should handle the null value in this. So in the task i cut the part of a word and i delete or rename the file, but need another if element for null. For example: I ...
0
votes
1answer
39 views

How can I replace a filename with .ear in a file-list using sed?

I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear ... I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck: ...
0
votes
4answers
121 views

sed Remove lines ending in [0-9]%

I'm writing a script that logs stdout-stderr. The log contains multiple instances of: (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading ...
2
votes
2answers
169 views

How to delete comments for java project with sed?

I have a Java project, in which I have JavaDoc comments /** ... */ other multi-line-comments /* ... */ line comments // ... and my own "explanatory comments" //* ... When I release my ...
-1
votes
4answers
71 views

How to break a string into smaller substrings with a condition on their lengths?

I have a file that contains some genetic sequences like this one: ...
3
votes
3answers
77 views

How to remove duplicate lines that begin with a pattern and the next line after that?

I want to remove duplicate lines that begin with > and the next line after that. For example: >1 ACCGGTTTCCTTGAAATT >2 AACCTTCCGGTTAATT >3 AACCTTCCGGTTAATT >1 ACCGGTTTCCTTGAAATT ...
2
votes
1answer
80 views

Named serial increment SED oneliner

I need to increment named serial and I want to do it with sed. I've done it like this: echo 2015092315 | gsed s/20[0-9][0-9][0-9][0-9]*/`date +%Y%m%d%H`/g But then I realized that updates to zone ...
0
votes
2answers
50 views

SED Multi-line substitute and hold space

I had some time to try and learn more SED this week and have been experiment with the following sample code: </td> <td> <h4 class="text-danger" style="display: ...
1
vote
2answers
224 views

Extract data between two matched patterns in a binary file

I am trying to extract a jpeg image from a binary text file. I want to extract all data between 0xFF 0xD8 (start of image) and 0xFF 0xD9 (end of image) inclusive. Earlier, I have successfully run the ...
3
votes
2answers
232 views

split a large file to new file with unique file names

I appreciate your help if some one could help me with a script that could split a file into unique file names. I can do it with sed command eg, sed -n '/scaffold135_/w 135-scaf.txt' input file.txt ...
3
votes
3answers
127 views

Sed to edit header with the contents of another file

I am trying to replace an existing header in a file based on the contents of another file. File1 - names.in: name1 name2 name3 name4 name5 File2- Datafile.tsv: chr begin end genes genes genes ...
1
vote
1answer
36 views

Array from piped commands fails

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank. I'm trying to write a script that will auto-mount our ...
0
votes
3answers
38 views

Is it possible to replace </sys:String> with sed command?

I have been trying to replace with using this command sed 's/</sys:String>/ /' but it doesnt work.
1
vote
1answer
66 views

Why is vi (but not cat) showing ^[[31m[^[[m^[[31m" after I use sed and output to a file I then edit? [closed]

When I use cat Variables/user-extensions.js | sed -e 's/css/XXX/' on an input file of the form storedVars["css_body"] = "css=body"; storedVars["css_main"] = "css=main"; I see output such as ...
3
votes
7answers
110 views

How to replace line with file contents and around the content with some text?

I would like to combine VPN certificates into a single file. This is a template file: # some unrelated stuff ca ca.crt # other unrelated stuff And I want to replace line ca ca.crt with the ...