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

learn more… | top users | synonyms

0
votes
2answers
26 views

Unable to perform a simple multiplication in script

I am havingf trouble performing a simple multiplication in my script. while read A B C do tmp=$A\*$C/100 echo $tmp >> out1.txt done < foo.txt foo.txt: 13721725 99 100 ...
7
votes
7answers
252 views

How to efficiently split up a large text file wihout splitting multiline records?

I have a big text file (~50Gb when gz'ed). The file contains 4*N lines or N records; that is every record consists of 4 lines. I would like to split this file into 4 smaller files each sized roughly ...
2
votes
4answers
91 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...
0
votes
2answers
45 views

How to find and replace only a particular word (which is at the end of the file) using shell command?

File1: Dms 01.01.2015 feeder1 6kv close at 04:30 Updated Dms 01.01.2015 feeder1 6kv open at 06:20 Updated Dms 04.02.2015 feeder10 6kv close at 17:23 Updated Dms 04.02.2015 feeder12 6kv ...
1
vote
3answers
72 views

Match beginning of a line with something there?

I want to match the beginning of lines where the line contains something. Command in Perl/Sed 's/^.?/\section{}/g' but the problem here is that it replaces also the first character of sentences. ...
1
vote
3answers
45 views

How to grep between words in a log?

I have a txt file with lines like below. Starting With: Parameters: {"raw_message"=>"MSH....... Ending With: </HL7Message>"} I'm wanting to grep and output to a file the words between ...
1
vote
1answer
57 views

How to write data one by one from tmp files to the final output file using for loop?

I have two tmp files named tmp1 and tmp2 which contains some lines. tmp1 file, 1c\ datafile no. 23 2c\ datafile is ok tmp2 file, 3c\ datafile no. 24 4c\ datafile is ok I have a ...
2
votes
5answers
120 views

Adjust gap between 2 columns to make them look straight

file1.txt: hi wonderful amazing sorry superman superhumanwith loss file2.txt : 1 2 3 4 5 6 7 When i try to combine using paste -d" " file1.txt file2.txt > actualout.txt actualout.txt : hi 1 ...
1
vote
2answers
27 views

Addition of values

foo.txt: Lillypaul_sg 204803 204803 204803 Ammy_sg 3 ramaswamy_sg 3 33 tommy_sg 3 3 137374 100 Desired Out.txt : Lillypaul_sg 614409 Ammy_sg 3 ramaswamy_sg 36 tommy_sg 137480 The output is a sum ...
2
votes
3answers
37 views

Truncating the precision of a date

I'm working with a bash script which polls build progress from several different systems. If a build is complete, it stats a log file to find out the last time it was edited, then feeds that time into ...
1
vote
3answers
51 views

Search word preceded by Name in Sed

This thread is motivated by the arithmetic command found in the link of this thread here in Sed. So I would like to do backward arithmetic in Sed. Data Mikael symptom David symptom hello symptom ...
0
votes
1answer
37 views

How to remove certain number of lines every time particular string is found in file

I want to remove 1 previous line and 10 following lines every time a string was found in the file. foo.txt: } Name: john Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 Line 12 ...
4
votes
2answers
101 views

Replace 1st with 1), 2nd with 2), … in GNU Sed

Pseudocode which is a continuation from this answer gsed 's/|/1)/g' 's/|/2)/2g' 's/|/3)/3g' 's/|/5)/4g' 's/|/5)/5g' <input.csv >output.csv which is of course not working. I am interested in ...
1
vote
2answers
48 views

How to print few lines from middle of a file using unix shell commands? [closed]

My file containing the following lines, $BQ { VOL @home } database daba relation tcdeatid opendb clear .lruno := 72 <-- (This line lruno. := 72 has 10 times ...
5
votes
8answers
648 views

How do I delete the first n lines and last line of a file using shell commands?

I have a file named Element_query containing the result of a query : SQL> select count (*) from element; [Output of the query which I want to keep in my file] SQL> spool off; I want to ...
1
vote
3answers
72 views

Sed Replace at a specific group of positions

I have a sample input file as below: Apple Orange Gold Silver Spoon Apple Orange Gold Apple Apple Orange Apple Orange Mango Gold ...
3
votes
2answers
84 views

shell script to extract between characters

I would like to extract a user name from the file between the keywords "/" and "NET" like below. How can I do so with programs like awk, sed or cut. from: audit: command=true ...
3
votes
4answers
223 views

Extract paragraph separated with *** using AWK

I have a file like below: blablabla blablabla *** thingsIwantToRead1 thingsIwantToRead2 thingsIwantToRead3 blablabla blablabla I want to extract the paragraph with thingsIwantToRead. When I had to ...
-2
votes
4answers
61 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will ...
3
votes
4answers
86 views

To remove newlines after empty line

Data 4. Alendronic acid A. Antiosteoporotic agent. B. Inhibit osteoclast formation and function by inhibiting FPPS enzyme, so increase bone mass. C. Osteoporosis in combination with vitamin D. ...
-2
votes
1answer
54 views

Remove everything else after this mark?

Data C. Induction anesthesia, muscle relaxant, anxiolytics, 1st line sleeping disorder (but short time in market). \part{Theoretical Questions} Lorem Code cat ...
3
votes
7answers
147 views

Insert a word in the first line of the file

Input: firstline secondline thirdline ...some magic happens here... :) Output: insertedtextfirstline secondline thirdline Question: How can I insert the insertedtext to the start of the first ...
2
votes
2answers
58 views

Inserting into middle of a string using sed

I'm trying to insert a string into multiple lines using sed, but i don't get the desired result I have this: <p begin="540960420t" end="600189590t" xml:id="subtitle8">-Some ...
1
vote
1answer
41 views

Insert variable in specific place using sed

Please help me i'm trying to insert variable in a file with sed but has not yet successfully(( I have variable $time and i want insert it in index.html file in specific string(line number 53): the ...
3
votes
4answers
244 views

How to use sed command to modify a file's entry line by line in shell script?

This is my file1: #$BQ #{ VOL @home } #database daba #relation tcdeatid #copy 1 #{ version 0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info ...
4
votes
3answers
111 views

Convert /proc/cpuinfo to a JSON in linux bash

I'd like to convert the entire entry of a cat /proc/cpuinfo to a JSON of "key" : "value". Is this possible? I tried to explode the string using \n in hopes that I could get each line and then I could ...
2
votes
4answers
67 views

remove the content from the beginning to the first blank line

I'm trying to remove the content from the beginning of the text to the first blank line. --($:~)-- cat example.txt pedro pablo juan francisco emiliano martin So, I would delete: pedro pablo ...
4
votes
5answers
108 views

Multiline Text Processing : Editing sshd_config

I have multiple blocks at the end of my sshd_config files like theses: Match User FOO ChrootDirectory /srv/www/FOO AllowTCPForwarding no X11Forwarding no ForceCommand internal-sftp ...
4
votes
3answers
107 views

How to insert multiple blank lines after every line

I want to insert 5 blank lines after every line in my input file. foo.txt: line 1 line 2 line 3 out.txt: line 1 line 2 line 3 ... Solaris 5.10, nawk or sed.
0
votes
3answers
51 views

Extract value from one file and insert it into another file replacing some other value

I have two files, whose line numbers are not same. But in file1 I want to replace lines taking reference from file2 using sed command. In file1: tid.infno := 72 tid.setnr := 120 (This number 120 is ...
2
votes
4answers
143 views

Using Grep -o or Sed/Awk to Grab Snippet from Middle of String

I am watching log traffic and see regular abuse of the various image search engines, Bing particularly. Example URL: ...
3
votes
6answers
176 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
2
votes
3answers
54 views

Delete lines between 2 strings in Solaris

I want to delete all the line between two patterns using basic awk or sed. foo.txt : ---------------------------------------------------------------------- Cap in MB line 2 line 3 line 4 line 5 ...
1
vote
0answers
43 views

-e option in sed [duplicate]

I saw someone do this to replace "upon" with "eat" in a text file called oro. sed -i -e "s|upon|eat|" oro Question: what is the purpose of -e option in the above command? I tried with and without ...
2
votes
1answer
47 views

How to output a comparison of values in separate files

With the following two files available with build names and version numbers available: server.txt Build2 200 Build3 100 Build1 400 Build7 200 local.txt Build1 300 Build2 200 Build3 100 In my ...
4
votes
6answers
356 views

sed command to swap characters

My input file layout is: mm/dd/yyyy,hh:mm,other fields I need to format it as: yyyy-mm-dd hh:mm:00,other fields sample input: 01/02/1998,09:30,0.4571,0.4613,0.4529,0.4592,6042175 ...
0
votes
3answers
140 views

How to detect end of line with sed

I'm looking for a way to only execute replacement when the last character is a newline, using sed. For instance: lettersAtEndOfLine is replaced, but this is not: lettersWithCharacterAfter& ...
4
votes
3answers
225 views

Why are these curly braces necessary in sed?

I wanted to do a range limited search in sed so I tried sed -n '195,210 /add/ p' <file> Which gave sed: -e expression #1, char 9: unknown command: `/' Purely as a guess, I tried adding ...
1
vote
3answers
90 views

Print previous line after a pattern match using sed?

I want to print previous line,every time a match was found. I know about grep -A and -B options. But my Solaris 5.10 machine doesn't support those options. I want solution using only sed. Foo.txt: ...
2
votes
2answers
108 views

Remove first n lines from file with variable

The command below works for deleting the first 3 lines: sed -i -e 1,3d t.txt So I tried substituting the 3 with a variable in a script as below NrLines=$(wc -l t.txt) sed -i -e 1,"$NrLines{d}" ...
4
votes
6answers
158 views

Extracting lines based on conditions

Each line in a comma-separated file has 5 fields. a,b,c,d,e f,g,c,i, j,k,c,m,n o,p,c,r,s t,u,c,w, x,y,z,aa,bb How can I extract the lines which have c in the 3rd field and their 5th field is NOT ...
3
votes
3answers
115 views

To replace % marks but not \% in Perl Regex

I am thinking how you can replace [^\]% marks but not \% marks in the sed -command of this answer. I think look-behind is not necessary. My current Sed command but I think Perl is a must here cat ...
0
votes
3answers
100 views

Find all words beginning with Q

How do I search a text file and list all the words begining with Q? The file I am searching is Python source code. The closest I have found to a soulution is this question but that is not what I ...
2
votes
2answers
40 views

sed replace after matching character

I have to change a properties file containing the property: ro.product.firmware=0.0.1 with a new value that is coming from a function called in a different section of my bash script. I cannot get ...
0
votes
2answers
37 views

sed replace ;“ content with ';”

I have files that contain ;" and I need it replaced with ';" The following sed command does not work: sed -i "s/;"/';"/g" /root/bashy.sh How can I do this? The solution doesn't have to be sed.
3
votes
2answers
129 views

how to print field between the double quote

I have the following file conf.txt: perl /home/site/gen.pl "GG - W C1 Test - sai1" "15072" && ssh 13.4.93.103 perl /home/site/gen.pl "GG - W C1 Test - sai2" "15072" && ssh ...
1
vote
1answer
50 views

Is it possible to pass arguments to a sed script?

Consider a simple sed script foo-to-bar.sed: s/foo/bar/ and the simple invocation: sed -f foo-to-bar.sed some-file.txt Now, let's say I want to customize the replacement string (bar in this ...
1
vote
2answers
42 views

Re-print an array in a certain format?

I wish to take 10 random lines of file, which is 100 lines long. First, I randomly generate 10 integers between 1 and 100 (inclusive) with ind=$(shuf -i 1-100 -n 10 | sort -n) Then, I wish to use ...
0
votes
1answer
37 views

Move a range of words to the end of the string

I have the following string: "5 S comment=whatever Unspecific text fruit=apple animal=mouse sky=blue" I need to move to end of the string, all that begin with comment to the word text. The start ...
3
votes
3answers
86 views

Specific column level substitution

If I have a file with columnar entries, is it possible to substitute specific entries from a specific columns only and save changes to the same file?? Example a file abc.txt: SR|FRUITS|COLOR| ...