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

learn more… | top users | synonyms

3
votes
1answer
29 views

grep upto matching brackets

I have a file like this:- pin(ABC) { a b c d e f { abc } } pin(XYZ) { g h i j k { j k { ...
1
vote
2answers
14 views

rename a batch of files after reading from a source file

I have a directory full of over a thousand files and the names are bit long (and no pattern found in the naming style). I would like to simplify the filenames. E.g.: ...
0
votes
1answer
36 views

Why does this command not work on AIX?

I want to remove UTF-8 BOM from a file using this command: sed '1 s/\xEF\xBB\xBF//' old.java > tmp.java But it did not work. I am running with ksh on AIX 7.1
1
vote
2answers
36 views

How can I sort a .txt file by two columns?

Feb 7 domainserver dovecot[37495]: auth(default): od(tjones): lookup failed for user: tjones Above is a sample output of what I'd like to sort. I'd like to sort by date on the first column, but ...
3
votes
1answer
35 views

How to export data in the terminal to a file (e.g. csv file)

I am a complete beginner in using Linux and I would like to know how to export a bunch of data in the command line to a csv or spreadsheet file (or even text would work). Right now I am simply using ...
1
vote
1answer
34 views

grepping of common lines between two file based on specific columns values in case of multi matching

I want to match column3 of file1 & column2 of file2 , after that i want to print all column of matching lines in a single line, i know how to do it but the problem is that if there are not unique ...
1
vote
2answers
90 views

replace lines in a text with matching text

Original file 123|abc|heloo good morning friends|1|123|abc|123|abc 123|abc|heloo good morning everyone|1|123|abc|123|abc Replaced file 123|abc|heloo good morning freinds|1|123|abc|123|abc ...
1
vote
2answers
41 views

Using sed to replace characters between two patterns

I'd like to replace all the newlines after a line containing a given pattern with a tab. Input file: $ cat File1 NAME1 N1_info NAME2 N2_info I'm creating some flags at the ends of the future ...
0
votes
2answers
46 views

how to remove all double quotes from csv except specific field

I want to remove all double quotes from my csv but not the fourth field (because the four fields represent PATH of file) Please advice how to implement this by sed or awk or perl one liner , etc ...
2
votes
2answers
128 views

Replacing lines containing a pattern with sed

How can I replace a given character in a line matching a pattern with sed? For example: I'd like to match every line beginning with a letter, and replace the newline at the end with a tab. I'm trying ...
-2
votes
0answers
12 views

Search and replace string literal with sed [duplicate]

I'm trying to replace a line in my preseed.cfg with a string that contains a bash variable that expands to include a password hash. I don't want to escape every special character in this password ...
2
votes
4answers
47 views

Combining sed statements

Let's say my input file looks like: ID1 1 5 6 8 ID2 1 4 5 7 I'm trying to formulate a loop that can combine these actions: If the line begins with a letter: keep the '\ n' after ...
6
votes
4answers
224 views

How to split long sed expression into multiple lines?

sed 's/[long1][long2]/[long3][long4]/' file.txt I would like to split this command onto multiple lines - f.x. something like this: sed 's/ [long1] [long2] / [long3] [long4] /' ...
6
votes
5answers
495 views

What's wrong with this sed expression?

$ echo "104_Fri" | sed 's/^\([0-9]+\)_\([A-Za-z]+\)$/\1;\2/' 104_Fri I would like to match the digits at the beginning and the letters at the end - each as a group. Afterwards I want to output the ...
2
votes
2answers
66 views

Replace column entry with sum of other column entries

Let's say I have a file that contains these lines: 02.03.14 14.50 14.50 0.00 Desc 02.03.14 17.00 0.00 17.00 Desc 01.03.14 2.82 1.68 calc Desc 02.03.14 1.04 0.00 ...
6
votes
5answers
158 views

Remove backslash + newline sequences

We are having a file in Linux which contains one line per record, but problem comes when the line contains some new line characters. In this case, the backslash is appended at the end of line and the ...
1
vote
2answers
74 views

Search for a string in a line and append related lines

I have a file containing some ID (identifier) and DS (description) lines. I'd like to keep the rows containing the string value in their ID line, as well as all the following (related) DS lines before ...
4
votes
2answers
123 views

sed to search for multiple words and remove those lines

I have a master file with more than 50000 lines and my requirement is to remove around 20000 lines from actual file, for this I used grep -vE command which is showing an error as too many arguments. ...
13
votes
9answers
435 views

Find all occurances in a file with sed

Using OPEN STEP 4.2 OS... I am currently using the following sed Command: sed -n '1,/141.299.99.1/p' TESTFILE | tail -3 This command will find one instance in a file with the ip of 141.299.99.1 and ...
1
vote
3answers
54 views

List all the html tags in a file

I want to know if there is a way to list all the html tags in a file. Lets say I have a file file.html <html> <head> <title>Test</title> </head> <body> This is a ...
1
vote
2answers
34 views

Format output to a specific line length

So I have some output that has very long lines, and I want to have it formatted to lines no more than 80 columns wide, but I don't want to split words because they are in the column limit. I tried ...
5
votes
2answers
268 views

How is the inplace modification of a file being done?

What does the "inplace" modification of a file e.g. via sed -i or perl -i mean? My question is about how this inplace modification is done. Is the file copied the modification is done in the copy and ...
2
votes
1answer
40 views

What package has GNU sed for Solaris?

I need to use the features of GNU sed, instead of the built-in version under Solaris 10. Which GNU package contains it? I don't see it listed in the coreutils, and my Google searches haven't helped ...
3
votes
1answer
62 views

Is there a way to pass a variable from an awk statement to a bash function as an argument? [closed]

I am trying to look a for some specific values from (such as 1 or 4 and 2 or 3) a text file using an awk statement in a bash script. If this value is found in the file (within the awk statement), then ...
2
votes
3answers
36 views

Reverse match in sed, replace opposite of what was found

Say I have this output from my syslog, precalculated src_hash => 20 bytes @ 0x7f811c001e20 A6 2D E5 CD 2A BA F0 42 56 66 19 D4 61 1A E3 A0 .-..*..BVf..a... C7 5E 5F 77 ...
4
votes
2answers
54 views

sed regex issue

I'm trying to replace a string in a file: $RELEASE = '1234'; The whitespace between RELEASE and the = symbol could be either spaces OR tabs. The quotes around the version number could be either ...
5
votes
2answers
176 views

Comment all lines from last commented line to line with 'foo'

Consider a text file users.txt: #alice #bob charlie dotan eric I need to comment everything from (exclusive) the last commented line until (inclusive) dotan. This is the result: #alice #bob ...
4
votes
3answers
107 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
4
votes
3answers
127 views

Regex alternation/or operator (foo|bar) in GNU or BSD Sed

I cannot seem to make it work. GNU sed documentation says to escape the pipe, but that doesn't work, nor does using a straight pipe without the escape. Adding parens makes no difference. $ echo ...
1
vote
4answers
60 views

Simple sed replacement of tabs mysteriously failing

This ought to be really simple, but for some reason it is not working: sed -i.bak -E 's/\t/ /' file.txt Instead of replacing tab characters, it's replacing t characters. I've tried every ...
5
votes
2answers
497 views

Does `sed` exist in all *nixes?

My application will be running on all versions of Unix-based OS, say, Linux, MacOS, HP-UX, Sun Solaris , OSX, etc. I'm using the following sed command in a common place to delete the string matched ...
3
votes
3answers
117 views

“Tuning” tr and sed expression

I have MD5 file which lists filename and MD5 sum in the following way: MD5 (file14n0001.xml.gz) = 04eb2524d271077ec8f1a0021779b171 MD5 (file14n0002.xml.gz) = 07e2b29645e9211cce9daf1ae27e7b99 MD5 ...
2
votes
3answers
132 views

sed + remove the first directory from path

Please advise on how to remove the first directory from a path by sed, (the inverse pf what basename does). For example echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed ... I should get: ...
2
votes
1answer
47 views

Removing non-printable characters using POSIX sed

Files created with roff and other "old-school" tools (for example man pages on many Unix systems) generate bold and underlined text in minimalistic terminals using tricks involving non-printable ASCII ...
1
vote
3answers
28 views

Delete whole line if after “:” less than 4 chars

I have a file with many lines, such as : blue:fish red:tomato black:moon I would like the whole line to be deleted if after ":", there is less than 4 chars. Thanks for your help!
3
votes
2answers
92 views

Counting comma separated characters in a row

How can I count how many elements are separated with comma in a given column of a file (tab_delimited), using awk or sed? Exemple: AC 1,23,5 DC 2,8,89 Would return: AC 3 DC 3
4
votes
3answers
98 views

Search and replace strings that are not substrings of other strings

I have a list of replacements like so: search_and -> replace big_boy -> bb little_boy -> lb good_dog -> gd ... I need to make replacements for the above, but at the same time avoid ...
0
votes
2answers
21 views

Replace selected caracters

How can one replace only the first [:space:] character in each row of a file with a \t using sed ? Input: AC 12 45 DC 56 89 Expected output: AC 12 45 DC 56 89 (Something like sed ...
3
votes
1answer
28 views

How do back-references match in sed?

I found a one-line sed command on this site which removes duplicate entries in $PATH. There is one concept that I can't get my mind around. It uses saved matches in the match section to detect the ...
2
votes
3answers
39 views

Merging multiple files by row

Is it possible to copy the rows of File1 and File2 in a new File4 following the instruction given by File3 by using a simple bash script (sed? awk?). File1: /*two or more columns, tab delimited*/ ...
1
vote
2answers
72 views

Replace columns using a shell

How could I replace column 1 in File1 with column 2 in File2, when a match is found? File1 id1 36987 id2 75685 id3 12345 id4 12896 File2 id1 ID1 id2 ID2 id3 ID3 id5 ID5 I'd like to write this on ...
2
votes
1answer
74 views

Compare the values of a column with all the values in another column

I have 2 input files. Each line of File1 should be compared to each and every line of File2. Logic is: If Column1 of File1 does not match Column1 (all the values under it) of File2, then print the ...
2
votes
1answer
25 views

SED and PDSH: adding a line to a file on a slave node in a cluster

I am trying to add a new line containing GATEWAY=10.0.10.1 to the /etc/sysconfig/network file on each of 32 slave nodes in a cluster. I read this post on how to insert a line with sed. This works for ...
0
votes
2answers
32 views

Using sed to remove string from list of files fails

I'm on bash (Mac OS X). I have a list of files and there's a string I want to remove: $ grep -l \</html\> *.html 21888601.html 21906283.html 21977081.html ... All matching files are ...
1
vote
3answers
63 views

sed - replace string with file contents

I have two files: file1 and file2. file1 has the following contents: --- host: "localhost" port: 3000 reporter_type: "zookeeper" zk_hosts: - "localhost:2181" file2 contains an IP ...
6
votes
4answers
143 views

How to insert lines with numbers from X to Y into another file after line Z?

I created two files: echo -e "1\n2\n3\n4\n5" > 123.txt echo -e "a\nb\nc\nd\ne" > abc.txt I want to get the file 123.txt with the following contents: 1 2 3 b c d 4 5 So in other words ...
3
votes
1answer
31 views

Matching several patterns on one line

I often use a program called tty0tty, which creates a null modem using PTYs. Now I want to make it part of an automated process. When I start tty0tty it prints (/dev/pts/1) <=> (/dev/pts/2) ...
1
vote
3answers
34 views

Sed + how to set parameters in sed command in order to display lines from text file

I find the following way to print line from file In this example we want to print the first line from the hosts file sed -n '1,1p' /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 ...
6
votes
5answers
227 views

Strategy to extract movies's name from this ununiform dataset?

I am working on a movie database problem to improve regular expressions, this is the problem I'm running into. My dataset looks like this: Movie Name (variable space and tabs) year Movie1(can ...
6
votes
2answers
151 views

Replace \n by a newline in sed portably

I'm so confused with GNU sed, POSIX sed, and BSD sed's myriad of options. How do I replace literal \n with the newline character using these three sed types?