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

learn more… | top users | synonyms

2
votes
1answer
63 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
46 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
261 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
96 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
68 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 ...
0
votes
3answers
149 views

Use Command Line Argument and Variable with sed Inside Bash Script

I have a bash script that takes a bunch of command line arguments. The only one that matters in this context is the first, $1, which is a text file. The header is very long, below are examples of ...
2
votes
4answers
46 views

How to append a line that does not start with '<' to the previous line

I have a log which contains XML lines. Sample format below: <head> <body> <line> asdasd</line> </body> </head> I want to scan the log file and ...
1
vote
3answers
64 views

sed doesn't distinguish between full regex match and no match

I want to extract portion of a string matching a regex. Consider the following code that works correctly: regex="ss" string="blossom" echo $string | sed "s/^.*\($regex\).*$/\1/" Output is: ss ...
0
votes
2answers
54 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...
2
votes
1answer
53 views

sed regex for capture group between delimeters

I have a two line file that I'm trying to get some info out of for a bash script using sed. # File Comment PrefixForInformation {information to be captured} I need to get the information between ...
1
vote
1answer
41 views

How to replace string in files using asterisk in search form

In my log files (*.log) I want to replace all occurrence of: "INFO=*", to "INFO=*;;;", where * could be anything. So, for example, "INFO=1234",S -> "INFO=1234;;;",S Is there a way how to do it ...
2
votes
3answers
132 views

How can I delete everything between two markers in a file?

I have a text in a text file, where I want everything that is between strings like \{{[} and {]}\} to be deleted - including these strings themselves. These two string can lie on different lines as ...
2
votes
1answer
31 views

need help with awk merging rows by sequence from multiple files into one file

have alot of files and need to merge strings between themself by groups of three files. each file ~100-500 rows and result file ~100-200mb seems like awk or sed can help me with paste or without it or ...
4
votes
3answers
152 views

How to match a pattern, delete the pattern and also the next and the previous line on Solaris 10

How can I match a pattern, delete the pattern and also the next and the previous line on Solaris 10? I'm hiting the wall because Solaris does not come with GNU sed. Given the following file content: ...
1
vote
1answer
58 views

sed, getting an error:sed: unterminated {

I'm using below sed command sed -n '\|<tag>|{:n; \|</tag>|!{N;bn}; y|\n| |;p }' test.xml OUTPUT: <tag> <name>jolly</name> <class>2nd</class> ...
0
votes
1answer
41 views

Use sed to edit code

How do I write a sed script that does the following: old(a,b) in the file should be replaced with new(b, 0, a) a,b can be any string with letters, spaces, digits, and these symbols: . / * - +
3
votes
3answers
70 views

How to use sed to write to a filename stored in a variable?

From within a bash script, how can I use sed to write to a file where the filename is stored in a bash variable? Output redirection won't do because I want to edit one file in place, pulling lines ...
-1
votes
2answers
50 views

First match if we are on the first line of input, if so print the whole line, else print the first word followed by a comma

for eg: CREATE TABLE MWWDATA.ACK997 ( AKTYPE CHAR(2) DEFAULT '' NOT NULL , AKNUM CHAR(9) DEFAULT '' NOT NULL ); CREATE TABLE MWWDATA.APREIDEXC ( EMPLID NUMBER(15, 0) DEFAULT NULL ); ...
0
votes
3answers
33 views

i want to print the line which starts with a paricular word and in the rest records print only 1st field

for eg: CREATE TABLE MWWDATA."VTCat02" ( "ID" NUMBER(10) DEFAULT NULL , "Cat" VARCHAR2(255) DEFAULT NULL , "Style_Code" VARCHAR2(255) DEFAULT NULL , "Vendor_Style_#" VARCHAR2(255) ...
2
votes
2answers
128 views

Refactor code using sed

How do I write a sed script the rearranges/refactors a string of characters of a file? The contents of my file are: for(int i=0; i<old(a, 10); i++) { sum += old(c*c, i*a) } ...
1
vote
4answers
75 views

How to get the number of each punctuation mark from a file

grep '[".?!"]' Returns the lines that have one of these but I have no clue how to tell how many are in each line, let alone how many ., ?, and ! there are.
1
vote
2answers
43 views

Use sed to format paragraphs for latex

I am using sed to reformat many plain text files to be compiled with LaTeX. The file contains various sections with keywords that provide a range. One of those sections I am working with is for ...
0
votes
2answers
62 views

Read a file and comment a line matching a string via shell script

Read a file and comment a line with matching a string via shell script I want to comment a matching line of file (final_ip) via shell script I have a input file (input_ip) if the searching ip is ...
3
votes
1answer
60 views

Replace Arbitrary Numbers of Word

Using sed, I want to replace patterns in the following way: --- >>> +++ --+-- >>> ++-++ --+-+-- >>> ++-+-++ --+-+-+-- ...
0
votes
1answer
146 views

Use sed replace with line number from variable

This is my sed command: while ...; do sed -r "${counter}s/^\S+ /$line /g" $in > $out; .. .. done Unfortunately this command isn't doing anything when called from within a bash script/loop. So I ...
3
votes
2answers
82 views

How to search for the word stored in the hold space with sed?

This is a sed-specific question; I am well aware it could be done with other tools but I am working on expanding my knowledge of sed. How can I use sed to globally quote (actually backtick) a word ...
0
votes
2answers
43 views

Combine rows from different files, if pattern is matched

Input: two tab-delimited files, File1 and File2. File2 ($2) has to be parsed by patterns found in File1 ($1). Expected output: tab-delimited file, File3. File3 has to contain the same rows as File2, ...
2
votes
3answers
260 views

unix: replace one entire column in one file with a single value from another file

I want to replace a column in one file with a single value from another file using unix. File 1 is a pdb file, structured like this: HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 ...
2
votes
5answers
504 views

Replace characters in user part of email address

I have a list that looks like this: user-name@domain.example user.name@domain.example user_name@domain.example ... I would like to replace any occurence of a dot in the username part. So that: ...
1
vote
0answers
23 views

line 24: unterminated `s' command assistance

I'm trying to get an sgml file processed using openjade and I keep getting this error: line 24: unterminated `s' command I'm not familiar enough with sed to figure out where there should be a ...
3
votes
1answer
36 views

Recursive find/replace, taking directory depth into consideration

I've had good luck doing basic find/replace: find . -name "*.php" -exec sed -i -e "s/<?php include 'http:\/\/www/<?php include '..\//g" \{\} \; I am wondering if there is a way to achieve a ...
2
votes
3answers
98 views

How to handle ^M in csv files by using sed & awk?

I have a file with delimiter ~, and was not able to load into database: Input file: 24~1~2~2~unsubscribed~wap~7~2015-10-23 20:03:00~2015-10-24 20:04:00~2015-10-25 02:53:26~Testing duplicate msisdn ...
1
vote
1answer
98 views

How can I run sed to replace lines in a file or do similar things in PHP?

I am writing a web frontend for configuring OpenWRT. I'm using PHP to execute commands and all the uci commands are executing without issues. However, OpenVPN configurations cannot be done via UCI and ...
2
votes
2answers
69 views

Are there any sed scripts built in to mainstream Linux distros?

When I was studying bash, I found it very helpful to go and study the bash scripts already present on a clean install of Linux—/etc/profile, for instance, and anything in /etc/rc.d/init.d/. These are ...
0
votes
1answer
47 views

Remove trailing spaces from first field only

I have a multi-lined, tab-delimited file like this: 99999bbbbbt999999bbt99t99t99t99 (where b=spaces, t=tabs) Trailing spaces in the 2nd field are ok, but the trailing spaces in the 1st field need ...
0
votes
2answers
41 views

Merge two lines of a file and adding number in the end of lines

I have a large text file abc.txt with the following format: BALT -6.110 130.600 4.06874414 -0.03254425 BALT -6.620 154.460 3.92286595 -0.17842244 BARM 32.740 140.680 3.94326190 -0.15802649 I need ...
7
votes
3answers
74 views

Remove certain characters from multiple files with whitepsaces

I'm trying to rename a bunch of music tracks in a directory, but I got this error: When moving multiple files, last argument must be a directory This is the script: for file in * ; do mv ...
1
vote
2answers
42 views

Extract keyword from line

I need to extract similar patterns from data below. The pattern starts with '.' or '' then to the keyword I want, then followed by ''. We can assume the format is LSUFE-numbers_ PCRF-numbers_ ...
4
votes
3answers
51 views

Inserting a text between 2 patterns

I have a .xml file which contains the below <controller-host></controller-host> <controller-port></controller-port> <tier-name></tier-name> ...
2
votes
3answers
340 views

Shellscript to remove particular tags in HTML file

Can anyone please guide me with writing Shell Script command for following scenario. I have an html file with all tags in a single line like this, ...