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

learn more… | top users | synonyms

1
vote
4answers
196 views

Add line to configuration file from a bash script?

I am trying to figure out to locate a line in a configuration file, then to drop down two lines then to insert a line of code. I was attempting to do this in awk/sed but got stuck on the carriage ...
1
vote
2answers
77 views

Complex sed Command with AND/OR/NOT

I have a bunch of php files which have many select commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is select * from users where abc='xyz' and ...
6
votes
4answers
223 views

CSV columnar reformat with SED (or anything other coreutil)

Given the following made-up segment from an output file from hashdeep: 7241,11111111111111111111111111111111,\01-data\file1 1237241,22222222222222222222222222222222,\01-data\file2 ...
1
vote
1answer
28 views

Replacing in files with sed using regex

i want to replace a string in many files like "Total:*points" using sed. I simply don't know how to use sed with regex. Below is what i got. Thank you in advance! find ./ -iname "skp-corr-*.txt" ...
1
vote
3answers
43 views

Transpose paramter values from a file and Generate parameter files from it

There's a file containing a table with the parameter names as the first line, values in the following lines: How to perform the following using awk, sed or any shell scripting utility: generate a ...
1
vote
1answer
55 views

substitute from beginning of line with 1 of multiple patterns to the end of another line with 2nd pattern

I have a file like this: data data data $globaltext blah gibberjabber somemorestuff etc ); data data data $otherjunk yada gibberish etc etc more etc ); My desired result is this file: data data ...
1
vote
3answers
124 views

Sed command with ' special character [closed]

I am trying to execute the following command from bash shell: sed -i "s/\(update.*\)where /\1 where primary_id = '$primary_id', /" *.php As you see, there is a variable which I am inserting using ...
5
votes
2answers
245 views

Command to remove the first N number of lines in input

Background I am running an SSH server and have this user that I want to delete. I cannot delete this user because he is currently running a few processes that I need to kill first. This is the ...
0
votes
1answer
60 views

Update phpmyadmin config.inc.php file in bash

When you download and extract latest phpMyAdmin, it comes with a config.sample.inc.php file. I would like to set a random blowfish_secret value on this line: $cfg['blowfish_secret'] = ''; /* YOU ...
6
votes
1answer
149 views

How to extract first base64 code out of file?

On Linux I'm having text files and each contains 1 or 2 base64 blocks of code. Following is part of the file and 1 base64 block. Content-Transfer-Encoding: base64 ...
3
votes
2answers
112 views

Merge and Append columns for more than 2 files

The files are tab separated. I have "N" number of files whose contents are as shown in the screenshot above. I want to merge them and append the 5th column. The first 4 columns are the same. I ...
1
vote
2answers
37 views

Return line conditonally on next line

I am trying to return a list of IP Addresses for computers that have a windows OS (for my security course). The output is in this format Nmap scan report for 192.168.xx.xxx Host is up (0.066s ...
1
vote
1answer
47 views

Use sed to retrieve variable from 1 file and place it in another

I need to use sed to retrieve a variable form within a file name. I am updating a previous code: cat /directory/filename1.xml | sed -e "s/XYZABC/${c}/g" > /directory/filename2.xml The value for ${c} ...
3
votes
5answers
235 views

split column after nth character

I'm trying to split my second column in the file below after every 4 characters. file.txt >1A THISISATEST >1B THATISATEST desired output: >1A THIS ISATEST >1B THAT ...
1
vote
1answer
58 views

Simulate sed read command with awk

I want to stimulate use of sed: sed '3r awk.scr' awk.script with awk.scr: a b c d e f and awk.script as: hello there is hello i'am there is hello sdfdf dfdfdf aads 23213 3 434 Using awk ...
1
vote
0answers
40 views

How to extract weather data from a html doc using linux string manipulation

I need to extract these info from this weather forecast site, but I don't know how much about string manipulation in linux: acm_RecentLocationsCarousel.push({name:"Irvine, CA", daypart:'day', ...
2
votes
2answers
60 views

How do I list all lines after two subsequent patterns are matched up to when they don't

I have files that are used to install files with specific owner:group and permissions. I'll ignore permissions for clarity and the details of installing files. Once an owner & group are set to a ...
1
vote
3answers
165 views

Read specified lines in file - BASH

I would like to read specified lines in file iptables. I want to read lines started with : and ends with space. File iptables # Generated by iptables 04:13:50 2015 *filter :INPUT ACCEPT [0:0] ...
2
votes
6answers
214 views

Use sed to find and keep only the lines with 2 alpha characters in them

I have a file with many lines like these 33B87401 33B87402 33B87403 33B8EE44 33B87405 33B87406 33B87407 33B87408 33B87409 33B8740A 33B8740B 33B8740C 33B87D0D 33B8740E 33B8740F 33B87410 33B87411 ...
1
vote
2answers
30 views

sed to match zero or more number of spaces in a string

function getVal { sedPattern='s/^.*"keyVal":"\([^"]*\)".*$/\1/' finalSedPattern=${sedPattern/keyVal/$2} echo $(sed $finalSedPattern <<< $1) } This is my Json parser written using ...
3
votes
4answers
123 views

Extracting strings from between special characters

I have a large text file created from combining lots of html files. cat *.html > all_html_files.txt Inside the text file are specfic strings that I want to extract to another text file. For ...
4
votes
1answer
166 views

In POSIX sed, does the period (dot) match a newline in a multiline pattern space?

In GNU sed it works. For example, this matches two blank lines in a multiline pattern space (created with N) /^\n$/ Is this standard?
3
votes
2answers
119 views

need to replace a file contents

I am stuck in a situation. I have a file script.txt with contents $cat script.txt SET TABLESPACE CONTAINERS FOR 3 -- IGNORE ROLLFORWARD CONTAINER OPERATIONS USING ( FILE ...
6
votes
2answers
530 views

Why does [0-9]* match where there aren't any digits?

so the command is : echo "abc 123" | sed "s/[0-9]*/h/g" and im getting output as hahbhch h how am i getting this output? the output i expected it to be is abc h which im getting by ...
10
votes
8answers
621 views

sed in-place line deletion on full filesystem?

Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
5
votes
7answers
607 views

Remove lines from tab-delimited file with missing values

I have a large (~900MB) tab-delimited text file that I will be processing in a downstream program. I need to delete any line with a missing value. The correct number of columns are on each line (so ...
-1
votes
1answer
119 views

bash - sed: -e expression #1, char 15: unterminated `s' command

I try to use sed command inside a loop to replace IP address, but it is always giving me this error: sed: -e expression #1, char 15: unterminateds' command` even it is not missing the end slash. ...
3
votes
2answers
28 views

vi — replace chars from part of line

I've got a file with all Belgian cities. Some of these cities have boroughs. Lier;stad;Antwerpen;49,70;33930;Lier;Koningshooikt ...
0
votes
1answer
45 views

Use sed to edit a line in a file with spaces in the name [duplicate]

I am looping through folders, opening a file within the folder with the same name, and doing some manipulation. I'm using sed to manipulate a line: sed "1s/Log R Ratio/$SAMPLE.LRR/" $FILE where ...
1
vote
1answer
41 views

Don't run this sed when a string is matched?

I have this sed command for deleting numbers inside of tags: sed 's/\(<[^0-9>]*\)[0-9]*\([^0-9]*>\)/\1\2/g' But does anyone know how I can exclude certain strings from this? Now it would ...
3
votes
2answers
65 views

Replace only on the first matching line with sed

Using BSD sed (no GNU extensions), how can I perform an operation similar to the example provided below, but where instead of the line number, the replacement is performed on the first line in which a ...
0
votes
2answers
44 views

Remove both lines if column A values are repeated in next row

My input is like this: pak_c35079_g1_i1|m.14890 Pfam pak_c20797_g1_i1|m.3458 ProDom pak_c20797_g1_i1|m.3458 Pfam pak_c28265_g1_i3|m.9595 TIGRFAM pak_c28265_g1_i3|m.9595 ...
1
vote
1answer
171 views

sed returns the following error sed: -e expression #1, char 101: unknown option to `s' [duplicate]

I'm writing a script to replace a label <p> with a path in some text files (*.prop). However , when I run it I get the following error: sed: -e expression #1, char 101: unknown option to `s' ...
1
vote
1answer
107 views

Remove leading 0 from specific field

I have a file with multiple fields but only want to remove the leading 0s from the 2nd column (col B) rather than all of the columns. I have tried: sed 's/^0//g' filename > new_filename but this ...
2
votes
5answers
42 views

Help on edit a sed statement

I'm writing a script to change on the fly the firefox home page through a text variable: sed -i 's|\("browser.startup.homepage",\) "\(.*\)"|\1 "$ddrs"|' /home/max/.mozilla/firefox/*.default/prefs.js ...
1
vote
2answers
66 views

Linux convert a number into a string on the 6th column

I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. Is there a way I can translate/convert a number to a string on my csv file. So ...
2
votes
2answers
224 views

Solaris using sequence generator at the beginning of each new line

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. I am trying to do a sequence at the beginning of ...
4
votes
2answers
166 views

concatenate n lines with sed

Recently, I asked a question how to sort pairs of lines, and one of the answers suggested concatenating lines with sed, like this: cat file.txt | sed -n 'N;s/\n//;p' | sort -t";" -k43,43n | perl ...
0
votes
1answer
35 views

In bash I'm unable to concatenate a string using a variable defined from output of echo + sed

I'm trying to concatenate a string with $result. Placing another string BEFORE $result results in the two strings not being concatenated: ...
3
votes
1answer
220 views

Using SED to cut after 7th character of each line

Just trying to cut any characters after the 7th on each line of a text. I initially tried this: sed 's/(.{7}).*/\1/' TestText.txt But got this response: sed: 1: "s/(.{7}).*/\1/": \1 not defined ...
0
votes
4answers
74 views

Why isnt this simple grep/sed script working [closed]

I have a variable with, among others, a line that looks like this iBMC=277 I'm trying to match that like this: BMC="$(echo "$allnow" | grep iBMC=[0-9] | sed 's/iBMC=//g')" This makes BMC empty. ...
3
votes
2answers
71 views

Two sed commands in one command

I have a file with a lots of names etc. and with spaces in between. Now, I want to delete all trailing spaces and all empty lines in this file with sed. I have two commands for this task but I would ...
0
votes
1answer
39 views

write variable into specific line with sed command

echo -n "##### STATIONS? #######" read station text="stab_site " I need to write echo $text$station into the 27th line of text file. I used below command but it didn't work, sed -i ...
1
vote
1answer
26 views

Use both a variable and newline in BSD sed?

I can do this for example sed 's/\>\</\>\ </g' To replace >< with > < However, say I want a variable, like this: sed 's/\>\</\>\ <$1/g' It will interpret ...
1
vote
1answer
56 views

Why doesn't this work when I add it to the current sed being run?

I have a text file that looks like this: (empty) str int int If I add this s/^/\</g to my current sed (making it 's/\&/\</g;s/\</\ /g;s/^/\</g') this is the output. < ##only ...
1
vote
2answers
56 views

Sed - How can I insert a string after a certain line AND a certain character?

I need to insert some lines of code into a file. The problem is, I want to insert it after some function calling AND after the semicolon behind it, too. I'd like to achieve this just with sed, but I ...
3
votes
3answers
82 views

Print all matching lines and the previous unindented line

For example, lets say I want to find all lines with 'matching' and the previous unindented lines in this text. Container 1 some text some text matching text some text Container 2 some ...
0
votes
1answer
43 views

copying a set of lines into new file

I have a text file with 100,000 lines or more. I want to copy specific lines from the text file into a new file using: sed -n '1,1000p;1000q' orig-data-file > new-file However, I want to create ...
0
votes
1answer
42 views

sed: multiple ranges between patterns, with one pass

I have a script that reads a file of about 3GB and sends it through a pipeline involving a very small number of replacements in a very small part of the file. To accomplish this with minimal overhead, ...
0
votes
1answer
62 views

How to replace word with unique prefix and suffix?

testfile starts with: abc: aprefixAnYthingasuffix This sed operation is NOT working: sed -i 's/aprefix*asuffix/mynewword/g' testfile testfile ends with: abc: mynewword ...