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

learn more… | top users | synonyms

1
vote
2answers
54 views

How can I comment out snmpmibd and snmpd in rc.tcpip in AIX using sed?

I need to comment out an entry in rc.tcpip file inside /etc # Start up the snmpmibd daemon start /usr/sbin/snmpmibd "$src_running" # Start up the Simple Network Management Protocol (SNMP) ...
1
vote
3answers
702 views

Delete lines from a file using awk or sed based on the variable from previous command

I have a CSV file (say temp.csv) with strings and numbers. I need to delete the lines which contain a particular pattern of string at the beginning of the lines in the file. For example, here is my ...
2
votes
1answer
51 views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: ...
0
votes
1answer
84 views

Escaping multiple backticks in a sed call

I need to perform search and replacement iteratively in several SQL statements: From: CREATE TABLE `Old_Name` ( To: ALTER TABLE `Old_Name` RENAME TO `New_Name` The above query contains ...
2
votes
1answer
56 views

How can I use a back-reference in place of a filename in sed?

I am trying to use sed to scan through a file and find a pattern, then use part of the matched pattern as a filename and insert the contents of the file at that location. I can get most of it to work, ...
0
votes
1answer
107 views

bash using grep and sed

This is for our weekly prac, no marking or grade (we don't even get the answers!) I'd really appreciate it if anyone has the time to help explain this exercise to me, as I'm trying to get this work ...
3
votes
1answer
191 views

Fastest `uniq` tool in linux

I have large text file (1.5 G), I want to know what the fastest and more reliable tool in linux is. I usualy use: awk '!x[$0]++' file.txt But when I use htop command I see my memory usage is ...
2
votes
5answers
239 views

Can the string “abcedf” be matched to string “bafcde” in a single line command?

I am planning to implement an indexing structure in my program. For example, if I have 100 rows in the table, I will number these rows from 1 to 100 in another column by appending an _ to the end of ...
0
votes
1answer
56 views

Using eval and sed to perform counting and script control

Following the original issue described here:- Rip chapters of a DVD to separate files ..would someone help us understand what the following code is doing:- # count Titles, and count Cells per title. ...
0
votes
2answers
56 views

Method to paste specific column when in terminal

I'd like to paste only the third column of data from within the terminal. I originally have something like: 4 SF0086 SF0086 12 SF0087 SF0087 17 TSF141 TSF141 29 TSF070 TSF070 30 TSF028 TSF028 31 ...
0
votes
2answers
86 views

How can I use Unix to rename all html files by their titles?

As in, rename all HTML files in a directory by the text contained in TEXT? Could a combination of grep, sed, and mv work? For example, I have a file contained 1.html. The title of 1.html is ...
2
votes
2answers
75 views

Sed? Stripping all formatting, i.e line breaks and whitespaces, from a report text file, while masking out certain pieces

I am working on a project in which I need to remove all formatting from a text file including whitespaces and line breaks, then replace any colons with pipes. I've made some headway but I cannot find ...
0
votes
3answers
35 views

Using sed to perform substitutions in a file

I was trying to replace dates in a huge file using sed. I tried : sed -ie 's/2014-[0-9]{2}-[0-9]{2}/2014-05-07/g' test However, nothing happened at all, my file test is not modified. Do you know ...
2
votes
3answers
707 views

sed, grep, or tr command that returns only Latin characters from a UTF-8 file

I am working with the text of the 300 tang poems, which unfortunately is a single file containing both Chinese and English. Since I am interested in 'extracting' the English, I hope to use sed, ...
1
vote
4answers
86 views

How to delete a line if string is the only thing on the line

How can I use sed or something else to delete a line only if the string I'm searching for is the only thing on the line? Example output: device-address-binding: ? database-revision: 20 -- ...
2
votes
6answers
242 views

How to search, replace and append a pattern to the end of each line

I have the following list of items: bigBone fishMarket dogCollar ... I need to generate a two character mapping like this: bigBone -> bb fishMarket -> fm dogCollar -> dc ... How can I ...
2
votes
4answers
126 views

How to sed -e 's///' everything except a specific pattern?

How can I substitute everything in a string with sed except % and any number directly succeding it? Meaning, everything except strings such as: %1 %1000 %55 etc. Best @devnull pointed out that ...
2
votes
5answers
354 views

How to delete empty comments with sed?

I want to delete empty Java comments like the following: /** */ /* * * * */ I tried it with sed, but the following deletes all comments, not just the empty ones: sed -r ...
-5
votes
2answers
76 views

Replace words in file using sed command

I have a file z. I want to replace string in File using sed command: 123: ' ', to: 123: '456',
2
votes
2answers
288 views

How to add a string with spaces at the end of command output

I want to add a string with spaces at the end of each line of the output of ls command. #!/bin/sh STRING_WITH_SPACES="this should be at the end of output" ls -lh | sed 's|$| '$STRING_WITH_SPACES'|' ...
4
votes
4answers
626 views

How to remove character and space from a string

Hello I have one file with output Name : ABC Name : CDE Name : ZYS I want to get the result ABC CDE ZYS How can i get it through SED command. I have tried. sed s/'Name' but ...
2
votes
2answers
157 views

How can I extract the numbers in the file using sed or any other tool?

I have a file that has this format [ 2014/05/01 10:48:26 | 13963 | DEBUG ] It took 11.16837501525879 seconds to complete the process So I have thousands of lines like this and I would like ...
0
votes
1answer
148 views

How do I use the SED command to remove injected code from multiple files?

One of the domains on my Centos 6.5 (64 bit) server has been compromised. Having run a detection script on the public_html folder I have identified all the files with this code injection. I ...
10
votes
9answers
1k views

How can I print the longest number in a string?

I am looking for a method to print the longest number in a string. E.g.: If I have the string 212334123434test233 how can I print 212334123434 ? Note: I am looking for the longest continuous ...
1
vote
1answer
117 views

Parse/Manipulate in awk

I am new to awk programming. I have a question on manipulating text file, which is required to draw certain network based images in a visualization software (Circos http://circos.ca) I have input ...
3
votes
6answers
493 views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
8
votes
6answers
378 views

How to get multiple lines out of a file by a regex?

How to get multiple lines out of a file by a regex? I often would like to get multiple lines / modify multiple lines by a regex. A example case: I am trying to read part of an XML/SGML file (they ...
1
vote
3answers
73 views

Are there any difference using pipes?

Using Ubuntu 12.04. Using pipes (5 times): $ time echo XYZ | sed 's/X/A/g' | sed 's/Y/B/g' | sed 's/Z/C/g' ABC real 0m0.005s user 0m0.000s sys 0m0.000s $ time echo XYZ | sed 's/X/A/g' | sed ...
5
votes
2answers
1k views

Cleanly swap all occurences of two strings using sed

Suppose I have a file that contains multiple occurrences of both StringA and StringB. I want to replace all occurrences of StringA with StringB, and (simultaneously) all occurrences of StringB with ...
1
vote
2answers
70 views

Parse,Manipulate Data In linux/Unix

I want to have exactly the same output in this post(http://unix.stackexchange.com/questions/126139/extract-data-in-linux-unix)as above,but I have a new input file,which is below: ABCB11 4 ACE 11 ...
1
vote
2answers
164 views

Extract data in linux/unix

I have input data which I want to parse and extract values using awk/grep/sed: group-2 9 10 text color=black,from=ABCB11,fromid=4,order=2,thickness=3,to=ACE,toid=11,use=1,z=1 group-3 0 1 text ...
7
votes
5answers
380 views

SED : Case Match Pattern Replacement

I have a source code spread across several files. It has a pattern abcdef which I need to replace with pqrstuvxyz. The pattern could be Abcdef (Sentence Case) then it needs to be replaced with ...
-2
votes
1answer
61 views

Comment multiple line using SED

Seeking help how can i comment multiple lines using SED, i like to comment ftp, telnet, shell, time, ntalk, daytime in inetd.conf file. Thanks in advance
11
votes
4answers
9k views

Delete last line from the file

I use sed to quickly delete lines with specific position as sed '1d' sed '5d' But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that ...
1
vote
5answers
256 views

Replacing backslashes with commas in Bash

I tried writing a script in which I am reading through a file line-by-line. I am supposed to replace a backslash (\) with a comma (,). The input file is as follows: 1,2,3,WORKSTATION1\A,5 ...
0
votes
1answer
44 views

How can I print a specific occurence of a range pattern?

I am trying to extract several data fields out of somewhat peculiarly formatted strings. Each string has a format similar to the following (spaces added for emphasis): 1 abcd 2 1 efg 2 hij 3 ...
2
votes
1answer
122 views

How can I make my sed command work on OSX as well as Ubuntu

I like customizing my PS1 prompt and including the current directory. I also have several other items such as time, user, git branch and the like, i.e. However one problem is that when my current ...
3
votes
2answers
373 views

How can I print out all but the last n characters in bash?

I'm working with standard input (cating two files together) and want all but the last 10 characters of the result to be passed through the next command. All I can find through searching is using sed, ...
0
votes
1answer
70 views

Want to replace the words with space in multiple files using SED commmand [closed]

Want to replace the words with space in multiple files using SED commmand I have a word as 'Danny' with single quotes in many of my files in multiple directories which I want to change to 'Danny ...
3
votes
3answers
180 views

Rearrange text file by prepending data rows with header row

I have a file whose content looks like this: 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 76.216 0.0400390625 0.00007 1.00000 0.9046 77.217 0.0400390625 ...
0
votes
1answer
43 views

removing the last line of a file not working? [duplicate]

I have this TXT file that is created by a bash script and at the end I want to remove the last line of that file that is an empty one. head --lines=-1 r3.txt > r4.txt sed '$d' r3.txt > r4.txt ...
5
votes
3answers
168 views

Extracting data from complex file structure

I have a txt file that is a dump from a database, that contains one entry per line. The structure is like this: 1500 29/03/2010 18 02 09 47 17 45 28.248 0 0.01 130 12.721 7908 298,809 YES ...
4
votes
3answers
3k views

Filter a .CSV file based on the 5th column values of a file and print those records into a new file

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , ...
1
vote
1answer
126 views

Searching for all the array elements in another array?

This is how I would search for an element in an array. count=${#ARRAY[@]} lsearch() { status=-1 for((i=0;i<count;i++)) do Temp=$1 if [[ $Temp -eq ${ARRAY[i]} ]] then ...
3
votes
2answers
613 views

Using grep/sed/awk to classify log file entries

I need to process a very large log file with many lines in different formats. My goal is to extract unique line entries who have the same starting pattern, e.g. '^2011-02-21.*MyKeyword.*Error', ...
1
vote
3answers
61 views

awk want to total by hour and variable

I am able to run this and it works fine - note: field $1 is a time/date stamped field.. gawk -F ":" "{ print $1 }" /cygdrive/c/counting/ourlog | sort | uniq -c | sort -r 57339 2014-03-21 09 54290 ...
3
votes
6answers
139 views

sed remove characters from new line

After some processing, I have my input file like below. file1.txt 12345|john|student 43321|jack|professor 78965|alex|lecturer I need to process the above file further and so I need a line ...
0
votes
2answers
80 views

Extracting with grep/sed a first pattern and then a second pattern that occured some lines before and related to the first

I'm trying to extract a specific line from a .htm file when a pattern occur ("Event 100" in my example below) but at the same time I need to retrieve also another pattern which is related to the first ...
-2
votes
1answer
45 views

sed query for pattern matching [closed]

My file looks like cat new: ALL ALLOFTHEM ALL1 OPS BE2A OPS1 ABE ABE ABE1 sed query below gives me the result as 1st line sed -n '/\([A-Z]\{1,\}\)\1/p' new: ALL ...
4
votes
7answers
521 views

How to split a filename list in 5GB sets?

I have a pretty big list of files which I like to group in smaller list of 5GB each for further processing. The file list is in the following form: "size" (from du) "tab" "absolute path", like this ...