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

learn more… | top users | synonyms

0
votes
1answer
31 views

Filter log on final letter in string [closed]

I have a below requirement to filter a word. My logs will be reporting with codes TML2345I,TML8383E & TML9929W. I want to filter the errors only with strings which have the last character as E. ...
0
votes
1answer
17 views

Print indentations with whitespace only in tree command

I want to list the subdirectories of a directory using tree command. But I don't want to print indentation lines. I only want to have the whitespaces instead. I couldn't find the correct parameter ...
2
votes
2answers
120 views

Curl url txt file, but grep each url seperately from single file

Ok, here's one for you guys that is puzzling me. So I have a text file with lots of url's in it. I'm using curl -K "$urls" > $output to spit the output to my output file. Now for the output of ...
2
votes
2answers
83 views

Insert text in specific lines of a file? with special characters

i know this has been answered several times, but i can't figure out how to use it for my project. i have several php files and want to add a new string between line 11 and 12. this is the string i ...
6
votes
4answers
144 views

Substitute Column With Result of Command

I'm trying to find a way to quickly and efficiently replace a column value for every row in a file with the output of a command. I need to work on multiple files with about 500,000 rows each daily so ...
9
votes
5answers
902 views

Merge two files line by line with the delimiter triple pipe symbol “|||”

I have two parallel files with the same number of lines in two languages and plan to merge these two files line by line with the delimiter |||. E.g., the two files are as follows: File A: 1Mo 1,1 I ...
2
votes
1answer
32 views

To Apply Answers to MCQs

I am now extending my own answers to MCQs, as made How to SED these paragraphs to MCQ format?. Data in file.txt 1 c 2 a Data in exam.tex \item Which of the following lorem ipsun are the best ...
3
votes
1answer
70 views

sed: cut line X and append to top of the file

I would like to be able to cut line X and insert the line X on position y (top). This would help me to be able to reorganize some config files. Text example line number 1 <--- Append line 10 ...
3
votes
2answers
63 views

Replacing strings in file using different values to replace the same pattern

I have such strings in my /etc/mail/virtusertable mail1@example.com error:nouser Account temporary disabled mail2@example.com error:nouser Account temporary disabled mail3@example.com ...
2
votes
4answers
43 views

Remove partial duplicates consecutive lines but keep first and last

I have log files with a time stamp and six values in each line i want to reduce the amount of data, by removing consecutive lines with the same values (ignoring time stamps) and keeping the first and ...
1
vote
0answers
105 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
1
vote
0answers
59 views

Why is sed changing permissions of a file on a cifs mounted share?

I have an Arch linux machine that uses the following fstab entry to mount a share: //192.168.3.1/Documents /mnt/ cifs ...
3
votes
1answer
62 views

sed -e 's/^[0-9]//' does not work for the first line

The following is the text I want to parse with sed (Mac OS X 10.11.1 bash) 1 00:25:43,959 --> 00:25:46,502 Here you are, sir. Main level, please. I can delete the first line with sed -e ...
3
votes
4answers
111 views

how to use sed when a variable contain '/' in it?

I have the following line to execute in a script and that delete two lines above it. But now my $TEST variable contain values like '/DATA/test10' and my variable ID contain '10'. How can i use this ...
1
vote
1answer
72 views

How can I replace a literal \n with a newline character? (on OS X) [duplicate]

I have a script which pulls something out of my shell history and saves it to a file, but if there is a newline in the history entry it gets returned to me with a literal \n instead of the newline ...
5
votes
5answers
217 views

How to SED these paragraphs to MCQ format?

My data: Question Nr. 311 Main proteins are in the lorem ipsun A Lorem RNA test B Cells C Metoclom D Cells E Muscles Question Nr. 312 Main proteins are in the lorem ipsun A Lorem B Cells C ...
1
vote
4answers
111 views

How can I delete multiple random lines from a text file using sed?

I want to delete 10 random lines from a text file that has 90 lines and then output this to a new file. I've been trying to do this using sed, but I have two problems. I'm using: sed -i $((1 + RANDOM ...
0
votes
2answers
59 views

How to execute shell command produced using echo and sed?

I have tried doing: echo " mv /server/today/logfile1 /nfs/logs/ && gzip /nfs/logs/logfile1" | sed 's|logfile1|logfile2|g' It printed: mv /server/today/logfile2 /nfs/logs/ && gzip ...
3
votes
1answer
30 views

Replace a control character with another control character

A csv file is being generated with a form feed (\f) character. This makes it hard to read in excel, etc. How can I convert the form feed character into a newline (\n) character? All my searches so ...
2
votes
1answer
70 views

How to find and replace using sed text containing a star *

I would like to find and replace text within many .procmailrc files, and using grep and sed. I would like to remove the following line (including the new line break at the beginning) from the ...
0
votes
2answers
22 views

Surround a pattern, not changing it, while searching for it case-insensitively

Sorry if this has been asked before, but I haven't found anything so far. Here's the thing: I have a string and a pattern, and want to surround the pattern inside the string with brackets. While I ...
0
votes
0answers
37 views

“Cannot reallocate” when create file?

Am trying to create excel sheet base on multifiles on a root, I read files line by line append in the final excel sheet. Am trying this shell script on small files and it worked 100% bu when I try it ...
1
vote
3answers
53 views

Is it possible to make sed doing some logic in the replacement part (regex group)

I have few sed command: to extract relevant information My file sample.log (format is ncsa.log) looks like: 2012_04_01_filename.log:29874:192.168.1.12 - - [16/Aug/2012:12:54:21 +0000] "GET ...
6
votes
2answers
403 views

Is sed \{x,y\} range greedy?

I would like to know if, for instance, \{x,y\} in sed will try to match as much or as little as possible characters. Also, can someone explain to me the bellow unexpected behaviour of sed? echo ...
1
vote
3answers
32 views

How to grep a heading in a manpage containing control characters

I have a manpage, and I want to find something in a specific section. Grep is having a hard time, and I figured out the issue was headings have control characters in them, e.g. SEE ALSO is really: ...
0
votes
1answer
53 views

Delete lines beginning and ending with a digit

I thought this was easy even for a beginner like me, but I'm stuck - piping a text file like this: cat file1.txt | sed '/^[0-9].*[0-9]$/d' > file2.txt This regex catches the lines in a text ...
2
votes
1answer
87 views

Modify filenames in Makefile

For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
1
vote
2answers
97 views

Using awk and grep for iftop results

I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips ...
2
votes
3answers
58 views

How can I use (sed|awk) to mask an e-mail address with asterisks like <j******e@g***.com>

How can I mask a list of e-mail addresses like: John Doe <john.doe@gmail.com> John Doe <johndoe@hotmail.net> Jane Doe <j.doe@outlook.org> ... with sed (or awk) into something ...
1
vote
3answers
107 views

Match lines beginning with the same pattern in two text files

I am now having two text files with some of the lines beginning with the same pattern. For example, File A 1Mo 1,1 I love you. 1Mo 1,2 I like you. Hi 23,3 I am hungry. Hi 23,4 I am foolish. File ...
0
votes
1answer
37 views

How to use the sed command in shell script [closed]

I want to replace the <name>, <place>, and <address> in my input file (for example, letter.txt): To : <name> Address : <address> Place : <place> with the ...
1
vote
1answer
100 views

sed and sudo with string replace

I want to replace a string with sed and save changes to same file which needs sudo as its a root owned file. But while doing that I am getting below error raja@raja-UbuntuVM:~$ sudo sed 's|gateway ...
0
votes
1answer
32 views

sed how to replace from standard input

I have to substitute (search and replace) a password field for files found in different directories. All fields are formatted as: field = value What I have attempted is: grep -i fieldofinterest ...
4
votes
3answers
156 views

Concatenate several files with a common header

I have several text files, and each file's content is like attribute1,attribute2,... 1,2,... The first lines which describe the names of the columns are the same in all the files. I want to ...
1
vote
0answers
28 views

tab-delimiting a file in shell

I have a file that I want to put in a table in SQL with 10 columns. I am trying to tab-delimit the file so that the file can go in the table. Here is part of my txt file: Chr12 MSU_osa1r7 exon ...
2
votes
1answer
62 views

Using sed / awk to change words between two patterns

I'm writting the shell script that should process through some text, I've got the text like that: read build { file1 file2 file3 } check build { file2 file3 file4 } read build { file4 file5 file6 } ...
-1
votes
1answer
38 views

extracting parts of a file to different file with sed

I am new at shell script. I want to write a script to extract parts of my data file and save it in different files. I wrote a script but it gives some error. The script is #!/bin/bash nn=0 mn=0 for ...
0
votes
3answers
60 views

Edit an xml file - Find a string then Delete a block of text / Find a string then Insert a new block of text

Morning All, I'm new to UNIX so looking to do something I can do in VB but don't have the experience to do in UNIX. I have an xml spec on a share which requires regular deletion and updates as new ...
0
votes
1answer
44 views

ssed -R versus perl -pe

If you want a sed with perl-style regular expressions, it seems that there are two ways to do it: ssed -R perl -pe Is there any reason to prefer one tool over the other for this purpose? They both ...
-1
votes
2answers
27 views

putting output into sql table

I am trying to convert the output of ps awux into 11 fields with the headers eliminated and then importing that output into an existing table in SQL.
2
votes
2answers
49 views

Replacing matching text after two matching lines

I have a YAML file which includes a stanza looks this: admin::common::passwords: alice: password: '$6$oTQhLvN/4VFJPscD$8LYwUMSFi' bob: password: '$6$JKOtLF0wHeZfIskt$W/M5.ugDS' If the ...
1
vote
3answers
255 views

How to extract XML from a text file

I have a text file as below. 1001=<?xml ns=dkfj><home><taga>dkjf</taga></home>1002=<?xml ns=dkfj><home1><taga>dkjf</taga></home1> I need ...
1
vote
3answers
49 views

Compare two files column values using awk

Here is the content of two files : Judi # cat File1 judi /export/home 76 judi /usr 83 judi # cat File2 judi /export/home 79 judi /usr 82 If column 3 of File2 is greater that column 3 ...
0
votes
1answer
94 views

print column value based on column name match in awk/sed [duplicate]

In my shell script after executing a few commands, I'm getting the output below: Name English Maths science Social studies ------ -------- -------- -------- --------------- James ...
3
votes
2answers
66 views

Remove headers and contents from a flat file if they are below a specific line count

I've a flat file containing about 10 million lines: query ID1 content1 content2 query ID2 content3 content4 ... content21 query ID3 content22 ...
1
vote
1answer
30 views

display users that logged in since a date using last

I am trying to display the user name of the accounts that have logged in during the past month using the last command. At the moment I have this last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul ...
2
votes
2answers
131 views

Delete row if two patterns are found in the same line

I'd like to delete a line from a text file (input.txt) if two patterns (string1and string2) are found on the same row, using sed. I'm trying: sed -i "/\b\(string1\|string2\)\b/d" input.txt, but ...
-1
votes
1answer
25 views

Reformat text contents into a CSV

I have a text file that I wish to turn into a CSV. The pattern of its contents are as follows: 1 mm/dd/yyyy LastName, FirstName MiddleName ID-NUMBER-HERE GENDER 2 mm/dd/yyyy LastName, FirstName ...
1
vote
2answers
60 views

Combine xargs -I with sed

I want to use find to find certain files and then use xargs with cp and sed to move these files to another folder and rename them. I know how to do this in a loop, but that is not what I am looking ...
0
votes
0answers
25 views

Sed - Replace a string that contains numbers

I'm trying to use sed to replace a line in /etc/hosts with a bash script. I know that when this script is ran, the string I want to replace is: 127.0.1.1 vanillabuild And here's where I've got ...