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

learn more… | top users | synonyms

0
votes
3answers
44 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. ...
3
votes
2answers
41 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
15 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 ...
-1
votes
1answer
27 views

Replacing string with value of variable using sed or awk

I want to change the value stored in the file by adding one (but without changing other contents) by substituting. v=`cat FILE |head -n20 \ |grep "Version=" \ |cut -d\= -f2 \ ...
0
votes
1answer
44 views

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

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
24 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
30 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
83 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
32 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, ...
1
vote
3answers
78 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
58 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
152 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
40 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
31 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
36 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
41 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
40 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
69 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
63 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 ...
1
vote
5answers
143 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
55 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
98 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
56 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
52 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
40 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 ...
13
votes
4answers
818 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
29 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 ...
-5
votes
2answers
61 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
42 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
29 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
61 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
489 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 ...
3
votes
2answers
102 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
54 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 ...
2
votes
0answers
55 views

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

I ran sed on a large file, and used the pv(1) 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, ...
0
votes
1answer
61 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
47 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 ...
1
vote
1answer
98 views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
1
vote
3answers
275 views

Why is '1,4p' outputing all the lines instead of just the first four?

I have a text file called "list" which contains some random words: he she we his her with his this this -- this this I ran this sed command: sed '1,4p' list What I thought this sed command was ...
1
vote
2answers
46 views

Insert line after matching line in sshd inside pam.d

I want to insert a line after matching line in sshd file which is present inside pam.d directory. For e.g. it should search for this line account required pam_nologin.so and it should ...
2
votes
2answers
114 views

how to grep for specific time period in a log

We work with log files that have line entries that start with a date/time format such as this: 20150408 13:29:28 <rest of text> What would I need to do in order to grep for a date range? Say ...
0
votes
0answers
26 views

seeking hints for correct escaping of sed commands WITHIN yaml

I am having a hard time finding the issue why following lines of "code" break my cloud-init config. Basically I am calling a son object as part of the DigitalOcean API which has a yam format - I got ...
2
votes
4answers
202 views

How to 'drop' characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
0
votes
2answers
35 views

How to scrape multiple IP's and add in a script as a variable?

I am trying to add in my script an awk statement or a: if; else; then if eth0:4 is a match then put in eth0:4 IP How would you get the IP in your script as a variable if you have multiple IP's ...
4
votes
3answers
130 views

Remove duplicate lines while keeping the order of the lines

[root@server]# awk '!seen[$0]++' out.txt > cleaned awk: (FILENAME=out.txt FNR=8547098) fatal error: internal error Aborted [root@server]# The ""server"" has: 8 GByte RAM + 16 GByte SWAP, x>300 ...
3
votes
4answers
236 views

Using sed for brackets

I would like to find out, if, in my file, there is a right number of brackets. I can make my file look like (((()))()(())) ((()))() How can I use sed to compute those brackets and print yes or no ...
1
vote
1answer
56 views

Output different lines when comparing two files

I have two text files with the same number of newline terminated strings. The lines in the two files correspond to each other. The lines in each file individually might be repeated. I would like to ...
0
votes
4answers
63 views

How to remove line based on Delimeter in perl / Shell?

Can anyone help to remove the line in file based on delimeter(Comma), Incase if line contain less number of columns or Bad records , Need to delete those. Input File: a,b,c,d a,b,d,f c,d a,v,b,h ...
2
votes
4answers
148 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...