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

learn more… | top users | synonyms

0
votes
1answer
18 views

delete line that contains a case insensitive match

I have a file that contains information as so: 20 BaDDOg 31 baddog 42 badCAT 43 goodDoG 44 GOODcAT and I want to delete all lines that contain the word dog. This is my desired ...
1
vote
2answers
55 views

Save file after using sed command

I am using following command to replace yyyymmdd to YYYYMMDDHH24MISS in my file: sed -e 's/\('yyyymmdd'\)/\('YYYYMMDDHH24MISS'\)/g' filename After I run the command in PuTTY, it displays the file ...
1
vote
1answer
33 views

Linux + capture only the IP's from mount command

please advise how I can to print only the list of the IP's ( in the end of the lines ) , from mount output mount netapp64:/lunggg/OracleTeam/OracleCDs on /oracds type nfs ...
1
vote
2answers
40 views

sed insert character at specific positions

I have hundreds of *.txt files which have a common format. I can insert a comma at a specific position in one file, how can I generalize the below code to apply this operation at several places for ...
0
votes
0answers
16 views

Word grouping using Sed and Regex [on hold]

I am trying to group words like A-D E-G H-L etc... Here is an example: 1099GHG (^[a-zA-Z0-9])(^.[a-zA-Z0-9]) 099GHG \1 == "1" \1/\1 1/1099GHG A-D/\1 E-G/\1 H-M/\1 N-R/\1 S-Z/\1 if (\1 == ...
1
vote
5answers
225 views

Grep value from json file

my json file looks something like this [{"product":"Apple","id":"2134"},{"product":"Mango","id":"4567"}] I want to grep/sed/awk 'id' for given 'product'. Output: Enter product : Apple Your ...
2
votes
1answer
18 views

grep awk or sed a CSV Row containing a certain part of a web address

I am trying to clean up a Squid log file and I want to delete rows with a website containing "/0/" in the 11th column. An example: Row1: column1, column2, column3...column10, ...
0
votes
1answer
37 views

Split string into array and print each element on a new line with commandline

I'm having a String which is seperated by commas like a,b,c,d,e,f that I want to split into an array with the comma as seperator. Then I want to print each element on a new line. The problem I'm ...
1
vote
1answer
34 views

splitting file based on values in specific column

I have a file that I would like to break up into multiple files with uniq values for the first column. For example, here is a file: fileA.txt 1 Cat 1 Dog 1 Frog 2 Boy 2 Girl 3 ...
1
vote
1answer
25 views

how can i comment out/in a section in source code with sed or awk

Currently i have files, which contain sections like this code statement1 code statement2 # BEGIN SOMENAME some code some other code # END SOMENAME code statement n +1 code statement n +1 What i ...
1
vote
3answers
71 views

Split a file based on required string

I have test file with the below contents: CREATE TABLE XYZ ( ABC INT, CDE CHAR(10), . . . ); Similarly, REPLACE VIEW XYZ ( ABC, CDE, EFG ); CREATE TABLE XYZ_1 ( ABC INT, CDE CHAR(10), . . . ); ...
5
votes
2answers
61 views

How to find one word and sequentially replace it?

I am running AIX 5.3(not by choice, but I cannot change it), and I have a text file: servers.txt Here is an example of the file's contents: apple port1 username password IPAddress TCP banana port2 ...
0
votes
3answers
38 views

How to find specific csv files and extract their second row into a single csv file

I'm trying to find out how to filter specific csv files by name and then extract their second row into a single csv file. I'm not sure whether it is a good idea to find files and then pipe it with ...
3
votes
3answers
135 views

Retrieving lines from a file depending on other lines

Imagine the following file structure: foo.bar.1 blabla moreblabla relevant=yes foo.bar.2 relevant=no foo.bar.3 blablabla foo.bar.4 relevant=yes I want to retrieve all foo.bar lines where within the ...
-1
votes
0answers
41 views

dump unstructured content of file to a csv or excel sheet [duplicate]

I believe it is not duplicate of other thread which we discussed in past. The reason being is: Here we have some rows (Virtual Disk, Physical Disk, device and shareddisk) which are repeating several ...
0
votes
3answers
73 views

How to group a bunch of rows based on information from the first row?

I have a data file looks like : 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 . . . 1 0 4 4 3 1 2 0 0 0 3 1 1 2 1 1 1 1 1 1 0 1 1 3 . . . 0 0 0 0 0 0 0 3 3 1 1 2 3 2 1 2 2 3 1 2 3 1 2 2 . . . ...
0
votes
1answer
23 views

Switch two arbitrary length strings separated by a symbol

I'm trying to split a filename consisting of arbitrary number of space-separated words into two separate strings by searching for the first occurrence of a symbol '-', and then switch the order of ...
0
votes
2answers
66 views

How to cut every line from a particular string?

input.txt: john_Apple01_xyz_1 john_Fruit_Apple01_abc_c1 john_Apple21_trs_1 john_Fruit_Apple21_efg_1 john_Fruit_Apple21_tefg_1 Desired output: Apple01_xyz_1 Apple01_abc_c1 Apple21_trs_1 ...
1
vote
2answers
46 views

Add columns to a text file with set spacing in Bash

I am setting up a malware zone file in DNS which will point all hosts to a specific IP. The file is simply a list of hostnames. This is what I have now: googlle.in ...
0
votes
2answers
71 views

how to subtract first value from the last one within a column across a row in shell?

I have a data file looks like : 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 2 4 5 8 9 10 13 17 19 29 30 32 33 50 700 800 900 950 first I want to insert space among each 3 identical values keeping each ...
7
votes
7answers
349 views

Convert rows to columns

I have a file that includes details about VMs running in a hypervisor. We run some command and redirect the output to a file. And the is data available in the below format. Virtual Machine : OL6U5 ...
-1
votes
0answers
26 views

dump non formated output of commands to csv file

I have some commands with which i can get list of VMs running on hypervisors. I redirect that output to some file.txt and use while loop to read each line from file.txt and execute two more commands ...
0
votes
1answer
38 views

How do I remove “^M” from a file? [duplicate]

I have two "identical" files that I compare in diff, and it shows that every line is different, after looking at the file I found that one of them has ^M at the end of every line. How do I remove ...
0
votes
2answers
19 views

sed + search word with strings and replaced all word

I want to create with sed the following: For example each word in the file that have the ssss... Should be replaced (all word) with target string as gggg. echo "duwdbnhb ssssssmnfkejfnei" | sed ...
0
votes
1answer
18 views

Insert Line in File When Group of Lines Changes

Let's say I have a text file like this: group1 hello group1 there group1 nice line group2 here group2 we group2 go What I want to do is insert a line when the group of lines changes, something ...
0
votes
1answer
41 views

sed appending filenames on newline

I am trying to add filenames to many *txt files, which are tab-seperated (they will eventually be joined together using cat) I am using bash, on Ubuntu 14.04. So far my code is; for f in *.txt do ...
2
votes
4answers
117 views

How to delete everything after a certain pattern or a string in a file?

Suppose I have a list of URLs in a text file: google.com/funny unix.stackexchange.com/questions isuckatunix.com/ireallydo I want to delete everything that comes after '.com'. Expected Results: ...
0
votes
0answers
74 views

How to redirect linux command outputs to specific row and column in csv?

I'm working on Unix Build post documentation process, I have a CSV file to be filled in and uploaded for every new build, to ensure the servers are build as per the original request. The CSV file ...
0
votes
1answer
41 views

How can I exclude the lines which matche the range patterns in sed?

I am writing sed expression which tries to print the text within a range of patterns: apt-cache showpkg gdm | sed -n '/Reverse Depends:/,/Dependencies:/ p' This basically works, current output is: ...
1
vote
3answers
25 views

How do I replace this pattern with a newline inside it? [duplicate]

If I have a text file with this content: someline <!--\ file first read on 2015/01/11 And I want to delete <!--\ and everything until what comes after "on", how do I do it? The ...
3
votes
2answers
39 views

How can I get rid of all script blocks in html files? [duplicate]

How can I remove all script blocks (including multi-line ones) from html files such as: <script type="text/javascript"> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; ...
-2
votes
2answers
52 views

How to use this script [closed]

#!\bin\bash for i in `seq 1 1000`; do wget -q -O quotes http://www.quotedb.com/quote/quote.php?action=random_quote; cat quotes>>final.txt; done I got this script from one website but I don't ...
1
vote
2answers
21 views

Copy plaintext lines from file and append them to same file with mid-line prefix or remove mid-line prefix

Making an ugly script that compiles a bunch of hosts files into one big list. Most lists will have two entries for a URL, one with www. and one without like this: 127.0.0.1 facebook.com 127.0.0.1 ...
-1
votes
1answer
50 views

Replace non-ASCII characters with space in a file

I am using the following command to replace the non-ASCII characters, single quotes and non printable characters: sed -i -e "s/'//g" -e's/&apos;//g' -e's/[\d128-\d255]//g' -e's/\x0//g' filename ...
2
votes
1answer
71 views

How to get filenames when using find and sed

I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified. This is how I am finding and then using sed: find . -type f -a ...
1
vote
5answers
262 views

To remove extra space from line using shell command

This is my file, TLRUIDA CBdms Status DP 6/1/1 DC 6/1/5 0 Y TLRUIDA CBdms Status DP 6/2/1 DC 6/2/5 0 Y TLRUIDA CBdms Status ...
0
votes
1answer
48 views

Using sed on files with certain extension inside shell script

I am trying to use sed to find files with certain extension and then replace occurrences of a certain string with another. No directory mentioned using current directory *.h sed: can't read *.h: No ...
1
vote
1answer
31 views

Searching and replacing a windows style path using sed

My task is to replace multiple entries for \\\\\\\\server\\\path1\\\\path2\\\\ with \\\\server\\path1\\path2\\ in myfile.txt (removing the superfluous backslashes). I have tried using sed for this ...
10
votes
3answers
891 views

What does sed -i '1d' do?

I understand that sed is a command to manipulate text file. From my Googling, it seems -i means perform the operation on the file itself, is this correct? What about '1d'?
3
votes
3answers
44 views

backreferences in `rename` regex

I have A LOT of files named "bar_foo.txt" in a directory, and I'd like to rename them to "foo_bar.txt" instead. In sed and vim the regex to to this would be something like ...
-2
votes
0answers
21 views

Complex sed Command for Insert Command [migrated]

I have a bunch of php files which have many insert commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is insert into users (ch_id, num_value) values ...
0
votes
4answers
69 views

How can I replace a character in all the .php files inside a folder on OS X?

I need to replace the following characters: ă with a â with a î with i ș with s ț with t The replacement must be case sensitive. For example if a letter is upper-case then it must be replaced ...
0
votes
1answer
38 views

What does :: do in script of sed

I would like to know what it really does with following scripts used with sed command. sed -e 's:<F0_M>:<o,f0,male>:' \ -e 's:<F0_F>:<o,f0,female>:' \ -e ...
-3
votes
7answers
107 views

Is there a way to prevent sed from interpreting the replacement string? [closed]

If you want to replace a keyword with a string using sed, sed tries hard to interpret your replacement string. If the replacement string happens to have characters that sed considers special, like a ...
5
votes
2answers
141 views

Remove hyphenation with sed

I have a simple xml file containing some hyphenated words over page breaks. The input is something like ba bla bla hyphe-</page> <page>nated bla bla bla and the output should look ...
5
votes
6answers
128 views

How to remove symbols from a column using awk

I have data like this: chr1 134901 139379 - "ENSG00000237683.5"; chr1 860260 879955 + "ENSG00000187634.6"; chr1 861264 866445 - "ENSG00000268179.1"; chr1 879584 894689 - ...
0
votes
1answer
13 views

How to remove a row if the difference between two columns is less than 2000

I have a dataset that looks as follows: chr1 HAVANA gene 69091 70008 . + . gene_id "ENSG00000186092.4"; transcript_id "ENSG00000186092.4"; gene_type "protein_coding"; gene_status ...
1
vote
1answer
45 views

Replace text quickly in very large file

I have 25GB text file that needs a string replaced on only a few lines. I can use sed successfully but it takes a really long time to run. sed -i 's|old text|new text|g' gigantic_file.sql Is there ...
3
votes
2answers
200 views

Conditionally delete a line from file

In a file that looks like: 549.432086168 0.0000E+00 9.6988e-04 2.0580E-02 1.0000E+01 9.6988e-04 2.0580E-02 2.0000E+01 9.6988e-04 2.0580E-02 . . . 5.6000E+02 7.0997e-06 -3.7538E-04 Delete the last ...
0
votes
2answers
108 views

How to remove a script tag from a text file with sed

I have a number of header.php files that have a malicious script tag contained within them (don't ask). I've written a not-so-elegant shell script to replace these with blank space. I had initially ...