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

learn more… | top users | synonyms

0
votes
3answers
34 views

Pad number within string and rename file [duplicate]

I have some filenames as such. a2.txt.gz d12.txt.gz k5.txt.gz m4.txt.gz ... one character followed by 1 or 2 numbers followed by .txt.gz. I would like to add single numbers with a zero before the ...
1
vote
1answer
85 views

Remove commented lines except one comment using sed

Not very familiar with complex usages of sed, but I have this requirement now. I have a file 1.txt with contents in the following pattern: sree@amby01:/home/sree : cat 1.txt SSL this first line #...
4
votes
4answers
322 views

How to print lines between pattern1 and 2nd match of pattern2?

Test file is given below: PATTERN1 a b c PATTERN2 d e f PATTERN2 g h I want to print line between PATTERN1 and 2nd match of PATTERN2: PATTERN1 a b c PATTERN2 d e f PATTERN2
0
votes
1answer
42 views

How can I remove duplicate entries in linux log

I've turned mysql general log on and I've been logging every transaction that occurs for the last week. I also have a cronjob running every 5 minutes doing some mysql transactions which is polluting ...
2
votes
1answer
45 views

sed unterminated `s' command [closed]

I'm getting: sed: -e expression #1, char 46: unterminated `s' command On this code: sed -i.bak -c 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward = 1|' /etc/sysctl.conf My editor is showing that ...
1
vote
4answers
56 views

Getting substrings in between delimiters multiple times from one string without looping

I have looked all over for a solution to this, but I couldn't find one. I am using qstat -x to pass a large string of job information. The output from qstat -x is in XML format. The substrings I am ...
3
votes
2answers
115 views

Add a line below each line matching a pattern only if not already present

Can sed add a new line below a specific content, if the input content exist then leave it ? Current content of the file ssss Hostname example.com Os version rhel5.6 apache 4.2 Hostname example2.com ...
2
votes
2answers
70 views

Retrieving five random items from a list using sed

How can I retrieve randomly selected five different items from a list using sed? My list is something like below. Each item begins with an asterisk at the beginning of a line. * asterisk* star ...
0
votes
1answer
44 views

when i used sed -n ,why this err about sed -n ' $j,4800p' [duplicate]

LINEnum=$(grep -nr "#32" IM_DlCtrlRef.txt | cut -d : -f 1) for j in $LINEnum do echo $j sed -n '$j,4800p' IM_DlCtrlRef.txt >> IM_DlCtrlRef_bak for insertl in {1..4} do ...
2
votes
2answers
25 views

less combined with sed color sequences prevents page breaks

If I use the command below which colors the lines output in yellow, it essentially turns less into cat, printing out the entire file and disabling all of the features I need with less, such as ...
1
vote
3answers
44 views

Reformatting negative numbers with sed or awk

I have a text file that contains some negative numbers except, they are formatted as: 00000012- With the hyphen after the number. I am processing the file using awk to reformat it into SQL insert ...
0
votes
1answer
53 views

Using multiple sed commands for text manipulation

I have a bash file, in which I would like to make several changes. sed -i 's/ / /g' testfile sed -i -e 's/#[a-z]$//' -e '/^$/d' testfile sed -i 's/ *$//' testfile sed '/##=/ r header' ...
2
votes
2answers
108 views

sed - find correct color sequence for ANSI extended 256 colors

I am currently using the following command to use the standard ANSI colors with the tail command: tail -f syslogfile | sed -e 's/\(.*MAJOR.*\)/\o033[93m\1\o033[39m/' This is bright yellow however I ...
0
votes
2answers
46 views

How to add a column of numbers to a array data file

I have a data file with two columns of numbers: input file 4.182 4.1843 4.184 4.2648 4.2281 4.0819 4.2204 4.1676 4.0482 4.1683 4.0156 4.2895 4.4504 5.2369 4.3776 4.4979 4.3797 4.1372 4....
0
votes
1answer
26 views

How to multiply two columns in a file by a constant number

I have a file like this. input data 4.2394 4.4569 4.2427 4.1011 4.2879 4.1237 4.2106 4.4844 4.2373 4.1071 4.1322 4.0502 4.3103 4.4255 4.4342 4.5262 I need to multiply each element by a constant ...
3
votes
3answers
41 views

awk to cut portion of a field and still print entire line

I have this line: 08:30:02.480507 IP 192.168.100.150.65119 > 192.168.100.151:53 59865 [1au] A? click.em.redbox.com. (48) I need to cut out the ".480507" in the timestamp so the line looks like ...
1
vote
3answers
84 views

Find and Replace with command line

my log.txt file includes ... mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 ... how can I replace mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 with mynetworks = 127.0....
1
vote
1answer
27 views

How to unwrap paragraphs using sed

I have a text file that contains paragraphs wrapped at 76 characters with an empty line between paragraphs. I'd like to use sed to convert this to a file that has one line per paragraph, no blank ...
2
votes
2answers
104 views

Extracting positive/negative floating-point numbers from a string

I am trying to extract numbers out of some text. Currently I am using the following: echo "2.5 test. test -50.8" | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' This ...
-2
votes
1answer
50 views

filtering pattern in a file using sed or grep

I'm new to Linux. I'd like to store all the unique usernames present in the extended.log file into a new file using the commands awk, grep, and/or sed. The following are the field-names in my file, ...
0
votes
0answers
30 views

shell scripting using sed

I want to compare specific string surrounded by alphanumeric and some special chars in file. For example: 5efa4083-7157-437a-ab9a-652ced2fc2ea;: AAA :;5efa4083-7157-437a-ab9a-652ced2fc2ea;BBB I ...
0
votes
4answers
47 views

Find a text in a file and Insert a text after it

I have a text file. The text file contains the below content. ServerName ServerAdmin webmaster@localhost DocumentRoot I need to insert a text www.mydomain.com, after the ServerName. Is there any ...
0
votes
1answer
76 views

Explanation of sed in shell script

I found a snippet of code online that would actually help with creating the frequency of each word in a text file however I would like someone to explain exactly how it is doing so Especially the ...
0
votes
2answers
34 views

Why you cannot have Tab in sed -i “1i \t 'word'” file?

Pseudocode printf "Masi \nwas \nhere" > /tmp/2 sed -i "1i \tword \t 'include word'" /tmp/2 Expected output: tab before the first word. Output: tword 'include word'. Trying to use variable to ...
1
vote
1answer
182 views

How to sed -i '`[echo $var]`i word' file?

Code: pos=2; printf "Masi \nwas \nhere" > /tmp/1 sed -i '`echo $pos`i huhu' /tmp/1 Expected output: Masi huhu was here Current output: sed: -e expression #1, char 1: unknown command: ``'
0
votes
1answer
44 views

Why Blank output of this `sed … <<END_SED | cut …`?

The following sed returns (...| od -c) without ...|cut -d "\n" -f 0000000 1 9 2 \n 2 5 0 \n 0000010 Pseudocode # http://unix.stackexchange.com/a/290407/16920 sed -n -f - /usr/share/...
2
votes
1answer
151 views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
3
votes
2answers
353 views

grep: How to find Closing Bracket?

One part of /usr/share/X11/xkb/symbols/us starts with xkb_symbols "dvorak" { and ends with the closing curly bracket }; which line-number I want to find. partial alphanumeric_keys xkb_symbols "...
2
votes
1answer
42 views

How can i replace multi line string using sed? [closed]

I have tried the following command:- [root@10 bin]# cat temp asdjahskjdhajksdhjkashjahfksjdhfkjsddhflkdsjhfklsdajhfklajshdkjalsdlkjasdhkljas hskdajkdhkjas cast $recv $UE_CAPABILITY_ENQUIRY ...
-8
votes
2answers
49 views

how to print in a single line with pattern matched

student:xxxxx student:yyyyy student:zzzzz student:kkkkk student:. teacher:aaaaa teacher:bbbbb teacher:lllll teacher:. student:sssss student:mmmmm student:. output should be, student:xxxxx yyyyy ...
1
vote
2answers
28 views

Insert text inside stanza at the end of the data string

I have a file I need to echo text into at the end of the file from the command line, the problem is the data is in a stanza, all within curly braces. This is the end of the file: text-string1,text-...
1
vote
2answers
46 views

sed: Grabbing and replacing all data between last backslash and a comma

I have data in a csv format that looks like this: F1309-042543,07/14/09 01:39:25,N/A,C:\windows\system32\netsh.exe,N/A,True F1309-042543,11/21/10 03:24:02,N/A,C:\Windows\System32\networkexplorer.dll,...
1
vote
2answers
46 views

Specifying comma-separated command line parameters based on text file lines

I want to run a command like: command argument --parameter=param1,param2,param3 where param1, param2, param3 may be any number of parameters coming from a file params.txt, each on one line. I can ...
3
votes
3answers
121 views

edit repo file with sed

I want to edit manually my repo file from the command-line, preferably using sed. How can I do that based on the repo-name I want to edit? I want to search for a specific repo-name (example: reponame-...
0
votes
3answers
35 views

Escaping regex sed (1 lowercase, 1 uppercase, 1 symbol, 1 number) for bash

The goal is to remove every line not containing one uppercase, one lowercase, one special character and one number from a file. I am unable to run this regex: (?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=....
0
votes
2answers
34 views

How to print lines using find and sed in multiple files?

I've many files in a directories structure. I want to extract some string (namely urls) by using a regexp, from those files. I've tried this : find . -path "*alder/ * / * .html" -print | xargs sed -...
2
votes
2answers
64 views

How to get the last occurrence of lines between two patterns from a file?

I have a log file which reports on the output of a process, I'd like to extract all lines from between the last occurrence of two patterns. The patterns will be along the lines of; Summary process ...
3
votes
3answers
238 views

Use sed with back references

I am trying to remove a space between 2 strings, they are like this: 312.2 MB 123.34 KB 487.1 GB I want to change them to: 312.2MB 123.34KB 487.1GB I've been trying and I can get: echo "312.2 ...
0
votes
1answer
44 views

help to analyse a log file

How does sed 's/\[//' work in case of analyzing log files for the time stamp fields? I found a solution online and I saw this line "$(head-1 "$1" | awk '{print $4}'| sed 's/\[//')". Can someone ...
-5
votes
3answers
103 views

How to add all the numbers of a specific column in UNIX without using awk command?

Let us take a sample file with the contents below, an expense report containing items and their prices: $ cat file Item1,200 Item2,500 Item345,900 Item20896,800 Item111,600 Now, a friend challenged ...
1
vote
1answer
42 views

Replacing variable containing \ with sed

i am trying to replace $old string with $new string in file where: old=ESX_10.1.1.1\@11.11.11.11 new=host_15_11_0_111.static I am using sed command: sed i "s/${old}/${new}/g" /filename but it ...
0
votes
1answer
40 views

Using sed to extract text between two strings [duplicate]

I have to use the AdaBrowse Html generator to create a bunch of formatted files. Unfortunately, all of these files contain headers before each function or procedure that follow no consistent form of ...
2
votes
3answers
54 views

How to delete a variable string in file

Actually I am using sed -e s/Perro-A//g -i *-a.log to delete the string Perro-A from many files ending with *-a.log. But sometimes in the files I might not have Perro-A; I might have strings ...
0
votes
2answers
35 views

Extract the second quoted string in a line of output

I have a line of output with three quotes, and I specifically need to extract the second quote into a variable. So for example, with the command cmd | grep tokens, I get the following output: Output ...
1
vote
2answers
55 views

How to check if some recurring text is missing in a text file?

I have a text file that looks like this: { "mimeType": "web", "body": "adsfdf", "data_source_name": "abc", "format": "web", "url": "http://google.com/", "urls": "...
1
vote
1answer
31 views

sed - pattern only on some predefined lines

I want to use sed to give me some lines from a file. I want to extract these lines only within some part of the file, which I know. E.g. I have a file with 100 lines, and I am seeking for lines ...
0
votes
3answers
41 views

Change CSV records sequentially

I want to replace the text sequentially in a file. The file's contents are: 1,01-JUN-2016,ABC 2,01-JUN-2016,ABC 3,01-JUN-2016,ABC 4,01-JUN-2016,ABC 5,01-JUN-2016,ABC 6,02-JUN-2016,ABC 7,02-JUN-2016,...
2
votes
6answers
118 views

Comparing 3 lines and 2 lines in BASH

I have a text file which looks like this. 2014-11-24 12:59:42.169 101.0.0.0 source 2014-11-24 12:59:40.375 104.156.80.0 destination 2014-11-24 12:59:36.729 104.219.48.0 destination 2014-11-24 12:59:...
2
votes
0answers
54 views

how to capture the latest kernel version from grub.conf

how to capture the latest kernel version from grub.conf ( in case default=0) for example the latest kernel from the file is 2.6.18-409.el5 # all kernel and initrd paths are relative to /...