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

learn more… | top users | synonyms

2
votes
1answer
26 views

How can I use sed to snip a line off of a string?

I'm writing a script to display the domain registrar info and I'm trying to snip off a few lines from what I already have I currently have it grabbing all the indented text from a whois. Now I'm ...
2
votes
1answer
18 views

Source of “gsed: can't read : No such file or directory”?

I have a Bash script that performs a simple substitution on OS X. Here's the reduced case: mkdir vs2005-dynamic cp cryptdll.vcproj cryptest.sln cryptest.vcproj cryptlib.vcproj dlltest.vcproj ...
2
votes
1answer
50 views

Join arbitrary lines to output as one line

I want to join the 3rd and 5th line of a file to the output of a script without trailing new lines. Is it possible to implement this construction by using the code: { echo 'Some text' echo 'Some ...
10
votes
3answers
669 views

How do you remove dot character from string without calling sed or awk again?

I have a file called hostlist.txt that contains text like this: host1.mydomain.com host2.mydomain.com anotherhost www.mydomain.com login.mydomain.com somehost host3.mydomain.com I have the ...
1
vote
1answer
50 views

Adding/removing some tabs and line breaks in an HTML code using sed

I want to refine an HTML code using sed, as an extra refinement procedure after refining it using HTML Tidy, as HTML Tidy doesn’t look flexible enough for some requirements. I used this command to ...
1
vote
1answer
26 views

How to append the first line at the end of each line of a file with Sed?

I'm trying to append the first line of a file at the end of each line with a single sed command: Example: line 1 line 2 line 3 line 4 should become: line 1 line 1 line 2 line 1 line 3 line 1 line ...
0
votes
1answer
29 views

Understanding sed expression

I am a beginner and would appreciate help on the interpretation of the sed+awk command below, sed -e '1,$s/ /:/g' -e '1,$s/;/:/g' |awk -F ":" '{print ...
-1
votes
1answer
32 views

sed and special characters [on hold]

I'm trying to use sed to replace </link> or </title> by a space in a file, I'm using. sed -i 's,</link>,,' file.txt if I use the same command but without the / it works, but with ...
3
votes
2answers
80 views

Organizing three dimensional data with awk/sed/perl

I have this file (a sparse matrix): PC.354 OTU1 6 PC.354 OTU2 1 PC.356 OTU0 4 PC.356 OTU2 7 PC.356 OTU3 3 I want an output like this (dense matrix -classic .biom table): OTU_ID PC.354 PC.355 ...
3
votes
2answers
36 views

Get a string and place it at the start of a line until the next string is found

I have a big non-standard xhtml file that i'm using sed (about 4 times) to iterate down to just the basics I need to throw the data into a MySQL database. My last bit i'm struggling with. The file is ...
1
vote
1answer
18 views

Library database

I have a database of readers and I would like to lend them a book and write it into the database. Example: Reader 753 Leonardo DaVinci davinci@gmail.com 321654987 Lended Books: grep ...
1
vote
3answers
49 views

Awk/sed: add line numbers to text from within a range

So I have a range, say 2-4. And I have three lines: first second third I need my output to be: 2 first 3 second 4 third I'm trying this on BSD (Mac) awk/sed, which seems to be making it harder.
0
votes
3answers
38 views

Extracting a date from a log file and creating a file with unique dates

I would like to extract from a file the date with format DD.MM.YYYY, date is always in the first place, here an example of the entries 15.04.2016 13:13:30,228 INFO [wComService] ...
0
votes
3answers
51 views

How to extract logs between the current time and the last 15 minutes

I want to extract the logs between the current time stamp and 15 minutes before and sent an email to the people configured. I developed the below script but it's not working properly; can someone help ...
1
vote
2answers
28 views

replace the content of one field based on the content in another field

I would like to divide the first column based on the delimiter, here -. Based on the last value, last column, here column 2, should be populated. If the value is 01 or 99 then replace with 2 or 1 ...
5
votes
3answers
18k views

Extracting part of lines with specific pattern using awk,sed

I have a question regarding the awk/sed operators. I have a big file which has following set of lines repeated Expression loweWallrhoPhi : sum=-6.97168e-09 Expression leftWallrhoPhi : ...
-1
votes
2answers
73 views

Have sed echo string after match

I need to have the string directly following/pbs.twimg.com\/profile_images\/echoed out. This is for a search tool I have created with a bit of help, and everyone recommends sed, but I never really use ...
2
votes
3answers
35 views

How to edit next line after pattern using sed?

Using sed, how do I search for a line ending with foo and then edit the next line if it starts with #bar? Or put another way, I want to remove a comment # from the next line if it starts with #bar ...
4
votes
2answers
318 views

How do I print the (numerical) ASCII values of each character in a file?

How can I print the numerical ASCII values of each character in a text file. Like cat, but showing the ASCII values only... (hex or decimal is fine). Example output for a file containing the word ...
5
votes
3answers
21k views

Using sed to extract text between 2 tags

I have a .xml file and I'm trying to do a "groupinstall" on a RHEL6 machine as there are several hundred libraries in that .xml file... (close to 16 000 lines). I'm therefore trying to extract the ...
1
vote
2answers
65 views

Removing spaces from the fields in a semicolon-delimited file using shell script

I have a csv file like this: 03139; 5; IT1234978208; 20150930 ; CTZ 13/31.12.15; 03137; 6; IT1234978206; 20151015 ; CTZ 13/31.11.18; .... .... 03134; 8; IT1234974406; ...
1
vote
3answers
96 views

Insert single quotes in text file for use as SQL query that follows the open-parens using sed

I have a where clause string in Unix file as below where c1 in (a) and c2 in (a,b,c) and c3 in () Need Output as where c1 in ('a') and c2 in ('a','b','c') and c3 in ('') Would be great if some ...
1
vote
1answer
31 views

Need help with sed/awk with deleting string

i have a txt file contenting the following information -Xmx4096m -Xms4096m -verbose:gc -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+ScavengeBeforeFullGC -Dsun.net.inetaddr.ttl=3600 ...
15
votes
12answers
1k 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 ...
0
votes
1answer
33 views

have a log file that I would like to break up into several files based on content

I have a log file that I would like to break up into several files Table of Contents *** Configuration Database *** Logs *** Configuration Logs *** Query Logs . . and so on The issue ...
0
votes
1answer
50 views

sed use from android shell

I am getting familiar with sed on the android terminal emulation: the version I am using the sed included in the toybox which is installed on my unrooted Sony device. sed --version (or toybox sed ...
3
votes
3answers
73 views

Replace a long string with the sed command: Argument list too long error

I'm trying to execute this command sed -i -e "s/BASE_64/$BASE_64/" FILE_NAME where $BASE_64 is a base 64 representation of a file content. sed gives me an error since the string is too long. ...
1
vote
2answers
74 views

Print text between multi-line delimiters

I am trying to extract data between 2 matching patterns, only if the content is not empty and I have issues doing it: here is an example: ============================== Queue Manager is : ...
4
votes
7answers
717 views

How to split a filename list in 5GB sets?

I have a pretty big list of files which I like to group in smaller list of 5GB each for further processing. The file list is in the following form: "size" (from du) "tab" "absolute path", like this ...
-4
votes
1answer
31 views

Can anyone explain in detail the following two commands regular expressions

The following two commands used to count no of non-zero integers of second column in the text file. Can anyone please explain the regular expression in detail. grep -c '^[^,]*,[^0][^,]*,' < ...
-1
votes
3answers
26 views

Count non-zero numbers for each row of a second column in a text file

I have a text file in that each line words are separated by commas, like this: 7022122465,0,\N,,0,2015-09-29 10:48:33 7022597642,0,\N,,0,2015-09-29 10:48:33 7022848906,0,\N,,0,2015-09-29 10:48:33 ...
0
votes
0answers
37 views

sed can't find file on a shell script [duplicate]

I've been running into a problem whenever I run the shell script containing a sed. If I try this argument by running the shell script with the following line, it gives me a bizarre error: arg=$1; ...
-1
votes
3answers
42 views

Insert array of years into a list of URLS

I have a list of URLS like the example below. /test/test I also have an array of years [1999, 2000, 2001]. I am trying to find a way to automate the task of printing out a list of URLS with ...
2
votes
4answers
338 views

How can I split a line into two lines if the length is greater than 7 using awk? [closed]

For example I just wanted to print something like this in the command line. Let say I have a file called file.txt. What is life? how are you? hi whatup this is more than And I want to print it ...
1
vote
2answers
41 views

sed + add last word on each string only if word not appears

I have the following file: linuxA.mtt.corp linux3V linux4B linux2A linux5v.mtt.corp how to add the .mtt.corp on each string that not have this word?
0
votes
4answers
3k views

Use SED or AWK to move rows to columns

I have a report that is generated in rows and I need to move it to columns. The number of rows per record will always be the same. This will be in a BASH script on Linux, so I would like to use ...
0
votes
2answers
89 views

parse HTML in Bash (when grep just isn't enough)

This is driving me insane, as I'm sure there must be some program doing the job but I just can't find it. To be noted, I'd be on ARM/Raspberry so unfortunately Xidel is not an option here, unless ...
3
votes
2answers
143 views

sed command with option -n and '$='

I want to print number of lines in a file using the sed command. I have the following line for that, please can any one explain in detail. sed -n '$=' myfile.txt
6
votes
5answers
5k views

Print line after nth occurrence of a match

I am looking to display the line 4598 in the following file. Effectively I want to display the line AFTER the nth occurrence of a match. In this case, the line after the 3rd occurrence of <Car>. ...
1
vote
2answers
38 views

awk + how to append list in file

I have the following list in file more file.ex efifc1a hygg4a hdy5d nhdw4s wesf3a fjfhyr jfhg gsfar how to append any second list after the first list and any third list after the second list ...
-4
votes
1answer
29 views

How to change certain word in certain line in a file [duplicate]

i have a file in which i have to change a word and then save it by same name. for ex- for file "name"- my name is joe (original data) my name is roy (changed data) how to do it in best possible ...
0
votes
0answers
25 views

RE error: repetition-operator operand invalid

I'm getting this error RE error: repetition-operator operand invalid On FreeBSD sed, using csh. Command is: sed -rn 's/.*?VIEW ([^\s]+?) (AS .*?)\s([^\s]+?)\s([^\s]+?)/DROP VIEW \1;\nCREATE ...
0
votes
0answers
34 views

sed using a bash variable [duplicate]

I am attempting to identify 2 lines a in a file, that match a pattern (path) $ dir_target="./CUSTOM/Database/XXRBS/DML/Insert" $ cat csv.out ...
0
votes
2answers
39 views

Renaming multiple files using sed

I have following set of files top_axi_256_wrapper_05.02.01.14.00_sample06.tgz top_axi_128_wrapper_05.02.01.14.00_sample06.tgz I want to replace 05.02.01.14.00 part with 05_02_01_14_00. So the ...
1
vote
1answer
39 views

Replacing mysql settings with sed

I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...) lines in db.txt. I have ...
0
votes
2answers
40 views

Can sed save its output to a file?

> can do it. echo "text" > file tee can do it. echo "test" | tee file Can sed do it without using either of the above? Is it possible to save the output of a sed command to a file without ...
4
votes
4answers
109 views

Replace strings in a file based on a list of strings and a list of corresponding replacements

I am trying to replace strings in a file A: Hello Peter, how is your dad? where is mom? where the strings to be replaced are in file B: Peter dad mom and their corresponding replacements are in ...
78
votes
8answers
111k views

How can I use sed to replace a multi-line string?

I've noticed that, if I add \n to a pattern for substituting using sed, it does not match. Example: $ cat > alpha.txt This is a test Please do not be alarmed $ sed -i'.original' 's/a test\nPlease ...
1
vote
1answer
22 views

How does this sed command works?

How does this sed line works : echo lred_6607: broken symbolic link to ./safaribooks/red_6607 | sed -e 's/^\|: *broken symbolic.*$/"/g' 1.There is no | character in the output of previous command. ...
1
vote
4answers
81 views

Impose character between repeated characters

Given a string of characters ,,a,,,b,,,, I want to impose the character - at the beginning, if no character is preceded comma, and between every comma that has no character. Meaning the result is ...