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

learn more… | top users | synonyms

1
vote
0answers
17 views

Escape >');} < / in sed

In 30 files in 30 directories, I want to find: script>');} < /script> and replace it with: script>');} < /script--> What special characters do I need to escape in the find ...
0
votes
0answers
16 views

replace long text string (script with MANY special characters). sed, awk, grep

My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
0
votes
2answers
21 views

sed + add comment to IP - only if IP is matched exactly

my target is to add "#" to the IP's with sed, But Only if IP is matched exactly!!! for example: sed 's/72.16.90.12/#72.16.90.12/g' /etc/hosts more /etc/hosts 72.16.90.121 host1 ...
1
vote
1answer
21 views

sed + update 4 different IP's in hosts file in one sed command

how to run the follwoing sed command in one command line? sed -i s'/12.1.0.11/#12.1.0.11/g' /etc/hosts sed -i s'/12.1.0.12/#12.1.0.12/g' /etc/hosts sed -i s'/12.1.0.21/#12.1.0.21/g' /etc/hosts ...
0
votes
0answers
25 views

Sed command for performance improvement or tr command for the same

I have a command to replace the non printable characters and single quotes from a file but its taking more time to execute as I am replacing these characters for multiple files and the files size is ...
0
votes
1answer
18 views

Remove file name when recursively counting number of occurrences of a pattern

When I run my grep command: grep -rc 'PATTERN' . it prints out the number of lines that the pattern occurs, but it looks like this: ./hotel_232424.dat:234 and so on... How would I remove the ...
1
vote
2answers
45 views

How to replace multiple blank lines with a specific non-blank line?

The sample input is 1 2 3 4 5 6 7 8 9 The expected output is 1 2 3 --- 4 5 --- 6 7 8 --- 9
0
votes
0answers
13 views

Delete Non numeric row from a csv

I have used sed to allow only numeric and csv format ,I have used sed '/[^0-9, -, .]/d' as regex. It has still "_","1-0","1-1" character as o/p which worries me. sed 's/'"$(printf '\015')"'//g' ...
0
votes
1answer
11 views

Trouble using if string in column 3 of .csv exist, then statement

I have a set of 10 files. 5 are unique tumors tissues and the other 5 are matching normal tissues… So {tumor_A, normal_A, tumor_B, normal_B,… tumor_E, normal_E} These files each have a random ID, ...
0
votes
3answers
27 views

List out the original IP Address of the host

I have following content in the file. I would like to print the IP address which is Under Name. Server: 17.128.100.12 Address: 17.128.100.12#53 Name: Testserver1 Address: 17.146.118.156 ...
0
votes
1answer
20 views

How do I use sed to change },{“Foo” to }\n{“Foo”?

I have a 55MB JSON file with a huge number of objects that are separated by },{. I would like to have one object per line and get rid of the comma. For one thing, I'd like to be able to look at the ...
0
votes
0answers
32 views

Multiple sed commands in a file

I want to save a .txt file to 2 separate .txt files using command placed in a .txt file. I can use sed -e '1,20 w file1' -e '21,$ w file2' input.txt But how would I plac e this command in a file ...
2
votes
0answers
49 views

Print some lines before and after pattern match excluding lines matching another patterns

I use awk on Solaris to print 5 lines before and after a pattern match. Currently, the following one-liner does the job: /usr/xpg4/bin/awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print ...
3
votes
1answer
25 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
0
votes
2answers
42 views

Collecting network information

I need to collect information about the network usage of each process. Nethogs presents the data I need in real time, I am trying to save the output to a file in order parse it and plot the data. ...
0
votes
4answers
37 views

Print only unique lines from file not the duplicates

I have a sorted words list, line by line file like so: apple apple grapes lime orange orange pear pear peach strawberry strawberry I only want to print out unique lines and drop duplicates: grapes ...
-2
votes
1answer
32 views

Read columns from file and substitute values in another file using bash script [on hold]

I have following file : input.txt b73_chr10 w22_chr9 w22_chr7 w22_chr10 w22_chr8 w22_chr8 I have written the following code(given below) to read the first and second column and substitute ...
2
votes
1answer
35 views

How to remove date format

I have the following content in the file. I would like to remove dates and the underlines from the file using sed. let me know if this would be possible to do with grep either. Can someone assist on ...
-3
votes
2answers
39 views

Convert all text in a file to uppercase using sed and interested to use range operator [duplicate]

I am trying to : Convert all text in a file to uppercase using sed and interested to use range operator. can some one please help me here. content of Sample.text: unix is great os. unix is ...
0
votes
2answers
26 views

Joining certain lines of text together before modifying them

I have a cricket commentary like - 0.3 Richardson to RG Sharma, 2 runs, gentle, non-swinging length ball on off, Rohit seeks to pick it up. Hit high on the bat and spooned over the returning Mitch ...
0
votes
1answer
19 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
61 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
36 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
43 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
17 views

Word grouping using Sed and Regex [closed]

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
244 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
19 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
39 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
35 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
75 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
68 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
39 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
78 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
67 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
47 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
83 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 ...
8
votes
7answers
356 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
27 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
39 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
123 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
78 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
26 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 ...