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

learn more… | top users | synonyms

1
vote
2answers
66 views

Delete text from a file using regular expressions

I have lots of text in a file. I want to delete all text that are between symbols === and <!!!>. E.g. Text ===some comments<!!!> lala ===aaa<!!!>" should be Text lala after running ...
1
vote
2answers
91 views

Search and replace multiple strings in a script using vim(search and replace) commands without sed?

A script that creates a file for weather precipitation is, #!/bin/ksh x=10 b=snow c=rain d=snow e=hail echo "$x,$b,$c,$d,$e" > weatherfile exit 0 given 3,8s/snow/dry/g For the search and ...
0
votes
3answers
56 views

What characters should I escape while modifying a file using sed? [duplicate]

I am using the following sed command(with word boundary): sed "7 s/\<<Filevalue=.*/>\>/<Filevalue="true"/>/" < config.xml And I am getting this error: sed: command garbled: 7 ...
1
vote
2answers
252 views

sed: problem while replacing string using wildcard

I am trying to replace a string using the following command: sed -e "s/\<$5\>/$6/g" "$2/$1" > "$4/$3" $5-> "hostname=*" $6-> "hostname=int1" $2/$1-> "source file path" $4/$3-> ...
0
votes
3answers
52 views

Vim replace in a visual mode

In a block of test like this cron.allow cron.deny I want to substitute cron with at,only in the range selcted by visual mode(ctrl+v) So i press ctrl+v : and appear the ! prompt ok I do sed ...
0
votes
1answer
59 views

Help in manipulating a test file

I have a file look like aaa/bbb/ccc.bbb aaa/bbb/ddd.bbb aaa/eee/fff.eee aaa/eee/ggg.eee I would like to skip lines ending similarly (where ending is defined by the extension, e.g. .bbb & .bbb) ...
5
votes
1answer
520 views

Replace non-printable characters in perl and sed

I need to replace some non-printable characters with spaces in file. Specifically, all characters from 0x00 up to 0x1F, except 0x09 (TAB), 0x0A (new line), 0x0D (CR) Up until now, I just needed to ...
0
votes
3answers
50 views

Read line from file and add that to the same line of another file

I have one file like this: aaa bbbb c And another one like this: 1 1241 2 301094209 3 432423 I want this: 1 1241 aaa 2 301094209 bbbb 3 432423 c so I can plot it with Gnuplot. If you ...
0
votes
2answers
70 views

Using sed, add line X lines above match

I know that to prepend/append something, I just have to do: sed -i '/pattern/a new thing!' However, I'd like to match a line, and prepend something two lines higher. I'd like to limit tools only ...
0
votes
2answers
50 views

Order the output using sed [duplicate]

I need your help using sed. I have this output after executing diff: < #R1#Number = Gauge32: 258 Name = STRING: "TATA" --- > #R1#Number = Gauge32: 280 Name = STRING: "TATA" I need to ...
-1
votes
2answers
63 views

Extracting certain data within a script output file

We have a script that runs several commands and rolls up all the output and inserts in into a log file. One of the commands it runs is "netstat -anp". I'd like to be able to search this file for all ...
1
vote
2answers
225 views

How would I use sed or awk to extract certain lines in a file

If I wanted to search for all lines in a file that start with a date, such as "May 1", how would I do that with sed or awk? I need to extract this data and either send to screen or a file. Thanks.
0
votes
4answers
173 views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
0
votes
3answers
83 views

Remove lines in a shell script

I have this file: # more file.txt 2c2 lns-ld-wall-01-t2 old:261,260 4c4 Prive_ORANGE old:258,259 I need to remove all lines like this one 2c2 and this one 4c4. How can I do in a shell script?
6
votes
3answers
135 views

How to use sed to manipulate continuously streaming output?

I am putting together a presentation for a non-technical audience. I have a program running in bash that outputs a continuous stream of values, a few of which are important. I would like to highlight ...
0
votes
1answer
30 views

How can I match and substitute this multiline pattern in a bash script?

I have a file jail.local and it has sections like this [apache] enabled = true logpath = /var/log/apache/error.log [ssh] enabled = false port = ssh I want to match on the string [ssh] and ...
0
votes
1answer
62 views

How can I use sed to print out unique users [closed]

I wish to print out the unique users in the system using only sed, using: ls -la | sed '/^$USER$/p' .... It gives me all files, matching to the current user, and prints out the lines they are in. ...
1
vote
1answer
40 views

How to filter a basic csv by columns

How do I filter by third column of the following file list.txt [[ list of people ]] billy baxter - @baxter - b.baxter@woods.com james woods - @woods - j.woods@someother.com I currently have cat ...
1
vote
1answer
44 views

Remove and replace between two specific strings using sed command

Hi I have a SQL file i wanted to remove case statements which are present in a single line as well as case statements which are present in multiple lines. For example, my input file is: Select a, b, ...
4
votes
4answers
143 views

sed to delete lines using multiple search string

I have a text file, let say test1.txt, I need to remove the line containing dog and date with "29-APR-2015" Using the below command to accomplish it but it is not deleting the lines. Where as if i ...
1
vote
2answers
46 views

How can I properly use the 'sed' s command in this particular scenario

There's a very simple question that's been bugging me about the sed command. Reading the documentation about this command has left me confused (mostly because English isn't my primary language). So, ...
2
votes
3answers
116 views

Using sed to consolidate diff output

I have this output as a result of comparing files with diff: < IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 260 --- > IF-Name :STRING: "lns-wall-01-t2" Index:Gge32: 25 I need ...
1
vote
3answers
79 views

Rename files (delete some characters that are not always the same)

I have some files named like this : DA1_ATGCATG_L001_R1.fastq.gz Oeu43_TCATGAC_L004_R2.fastq.gz I want to delete the part after the first "_" but keep the end of the names from "_R" to obtain this ...
2
votes
2answers
199 views

Extract group name from `id` and store it in a variable

$ id usera uid=830(usera) gid=799(groupa) groups=799(groupa) I need to extract the group name from the output of id and store it in a variable. In this case it's groupname=groupa
1
vote
2answers
59 views

Append words to wordlist with sort -u avoinding duplicata

I have 2 txt file called one.txt with duplicata: yesterday yesterday today today tomorrow tomorrow and the second txt called two.txt with duplicata: mike mike paul paul tomorrow tomorrow Using ...
0
votes
0answers
86 views

tmux status bar path customization with sed

On the server I connnect to my home path is like this:/home/junk1/junk2/user. I can use the sed command pwd | sed -e 's|^/\([[:alnum:]]*\)/[[:alpha:]]*/[[:alpha:]]*|/\1|' to shorten the directory path ...
1
vote
2answers
78 views

Using sed to replace javascript code in multiple files

I need to replace an old google analytics code with the new universal tracking code in lots of static html files. The old code looks like this: _uacct = "UA-XXXXXX-X"; urchinTracker(); The new code ...
0
votes
3answers
47 views

Find the row and append to the bottom of the file

I have a big file with some record which will be having different values than others. Actual data file: 000000106500000000000129201300000U1E4600000060000+00000020400+00000002532+000000 ...
0
votes
1answer
49 views

Add the number in the column if exists

I need to count Nodes_Util for each Queue. In the example below, queue1 has only one line, but it varies and it could be nothing sometimes and it applies to all queues. I want to dynamically add the ...
1
vote
6answers
92 views

Count the number of 0 and 1 in a file [duplicate]

I have a file (see below), and I would like to count the number of 1's and of 0's: 1 1 1 0 0 1 1 0 0 0 ... I tried to use awk but it doesn't work, for example, to count the number of 1's: awk -F ...
1
vote
2answers
68 views

How to strip time stamps from a file?

I have log which contains lines of data: Mon Apr 20 03:15:18 EDT 2015: my|data|data|data I am trying to write a script which would extract just the data from the log, stripping the leading time ...
0
votes
0answers
20 views

Sed replace with command output [duplicate]

I'm trying to replace text with the contents of a file and I'm getting errors. This works: cat /tmp/test | sed -e "s/__TEST__/$(cat pass)/g" But this one doesn't cat /tmp/test | sed -e ...
3
votes
7answers
388 views

How to add a line after nth occurrence of a keyword using sed?

Using sed, I want to add check after nth occurrence Input: DCR DCR DCR Output: DCR DCR check DCR Is it possible using sed?
1
vote
2answers
104 views

Removing special chars from file and maintain field separator

I've been able to remove all special characters from a fixed length file which appear in the first column but as a result all subsequent columns have shifted to the left by the amount of characters ...
3
votes
2answers
159 views

sed insert in the beginning of multiple files is not working

I came across a lot of answers, including theses: sed on OSX insert at a certain line http://stackoverflow.com/questions/14846304/sed-command-error-on-macos-x ...
0
votes
3answers
115 views

Filtering multi-lines from a log

Should this question be moved to stackoverflow instead? I often need to read log files generated by java applications using log4j. Usually, a logged message (let's call it a log entry) spans over ...
0
votes
2answers
105 views

Replace special characters with sed

I have to replace special characters using shell, so i use sed but i have some mistakes that i don't understand. <%_ by [@, ("_" = dash) _%> by ] for the first 2 characters my synthax is : ...
2
votes
1answer
78 views

ksh/bash Formatting Files through sed by cat file|sed command

I am new to unix platform, (Alternate Approaches can be discussed) I am trying to change the colors of content of a file conditionally. My file is: A B C D Value Value Value Value Value ...
14
votes
4answers
1k views

Is there an alternative to sed that supports unicode?

For example: sed 's/\u0091//g' file1 Right now, I have to do hexdump to get hex number and put into sed as follows: $ echo -ne '\u9991' | hexdump -C 00000000 e9 a6 91 ...
0
votes
1answer
42 views

replacing multi line string with another multi line string using sed

for eg. input : // copyright package com.base import com.base import com.base ... i want to replace the pattern "// copyright\n\n^package.*" with another string i'm trying to do using sed -e ...
-6
votes
2answers
75 views

How to average a column in a text file without using ' character? [closed]

I need to do it without using the ' character. I could do it like this: awk '{sum+=$5} END { print "Average = ",sum/NR}' except this contains a '.
0
votes
3answers
69 views

modify file using awk or sed

I have a text file contains ldap data in the give below format, our default structure says every user must have its own respective "home directory" but in given below i found many users have the same ...
1
vote
1answer
56 views

sed exception handling of escaped characters

I want to delete anything that follows a % to the end of the line. Using cat /tmp/foo.txt | sed 's/%.*$//' works great with one exception: I want to ignore any escaped percent signs \%. So with ...
1
vote
4answers
85 views

How to Remove Strings between two Parenthesis in Unix

I have a requirement like i have to remove the strings or numbers between two Parenthesis in a file. I used sed command but it is working on a single line. My opening Parenthesis is in one line and ...
3
votes
4answers
643 views

Is is possible to modify a file in a read only directory? [duplicate]

I have already read: Is there a way to modify a file in-place? I am curious if there is a way to modify a file in place using a command that will not create temporary files. Let's say I create a ...
4
votes
2answers
166 views

sed: inserting text before end of <HEAD> section

I need to insert some text into an HTML file before the end of the HEAD section. I'm trying: sed -i "s#</head>#<style> @page { prince-shrink-to-fit: auto } ...
1
vote
4answers
66 views

Sed substitution grouping is appending in OSX rather than the expected sub in Linux

I've got three comma separated columns. Last name, First name, social. I'm trying to capitalize all characters in the last name column using sed 's/\([^,]*\)/\U\1/' foo.file In osx this command ...
5
votes
1answer
114 views

Why doesn't sed exit immediately after writing the output?

I ran sed on a large file, and used the pv utility to see how quickly it's reading input and writing output. Although pv showed that sed read the input and wrote the output within about 5 seconds, sed ...
0
votes
1answer
188 views

Is there a way to use sed or awk to filter data inside a zipped file? [duplicate]

Is there a way to use sed or awk to filter data inside a zipped file? When I run a sed or awk command and send to stdout the file created is 0 bytes.
0
votes
1answer
54 views

Sed working with two lines

I would like to create a sed command that takes every two lines in a document and if the first line ends with [letter or number] and the second line contains dot (.) it will join these two lines ...