sed

AWK/SED remove columns that contain parenthesis

Hi all, I was wondering if it would be possible to remove columns within a data file that contain any parenthesis that can be contained in ANY column. For example ... John Doe (Tech Department) 09/12/2009 555-555-5555 Jane Smith 09/12/2009 555-555-5555 (Suspended) Alfred doe 555-555-5555 (Vacation) 09/09/2011 ... So then I would like...

replace a string in huge file by incrementing with it number of appearance in file?

I have a file of 500MB and it has strings : string_1 ..... string_500, I need generate the copy of this file which has : string_501.......string_1000 I need to do this up to string_500000, what's the best way to solve this? ...

shell script to parse log file

Hi, I am given a log file(see below), I need to make it to this format using bash script: title pdfspool date rip date bmpspool date CLAB date Sometitle12 10/09/23 00:56:40 10/9/23 0:56:46 10/9/23 0:56:50 10/9/23 1:01:13 log file !!Begin Source aserver:pdf_spool:the, Job 844b015e0043469e, Inst 844b015e0043469e T...

Regarding grep command

I have two queries I do a grep and get the line number of the input file. i want to retrieve a set of lines before and after the line number from the inputfile and redirect to a /tmp/testout file. how can i do it. I have a line numbers 10000,20000. I want to retrieve the lines between 10000 and 20000 of the input file and redirect ...

Repeating a regex pattern

First, I don't know if this is actually possible but what I want to do is repeat a regex pattern. The pattern I'm using is: sed 's/[^-\t]*\t[^-\t]*\t\([^-\t]*\).*/\1/' films.txt An input of 250. 7.9 Shutter Island (2010) 110,675 Will return: Shutter Island (2010) I'm matching all none tabs, (250.) then tab, then all no...

"sed" command in bash

Could someone explain this command for me: cat | sed -e 's,%,$,g' | sudo tee /etc/init.d/dropbox << EOF echo "Hello World" EOF What does the "sed" command do? ...

How can I swap two lines using sed (linux os)?

Hello stack overflow, Does anyone know how to replace 'line a' with 'line b' and 'line b' with 'line a' in a text file using the sed editor? I can see how to replace a line in the pattern space with a line that is in the hold space (i.e. /^Paco/x or /^Paco/g), but what if I want to take the line starting with Paco and replace it with t...

Concatenate Lines in Bash

Most command-line programs just operate on one line at a time. Can I use a common command-line utility (echo, sed, awk, etc) to concatenate every set of two lines, or would I need to write a script/program from scratch to do this? $ cat myFile line 1 line 2 line 3 line 4 $ cat myFile | __somecommand__ line 1line 2 line 3line 4 ...

converting IP ranges into discrete ip numbers using bash/awk/sed

I am processing IP source/destination/port lists created as acl requests The request looks some thing like this: source IP destination IP Port 76.211.12.9 10.112.12.232 1521 The Source and destination IP's have three distinct formats x.x.x.x,y,z x.x.x.x-z x.x.x.x,y.y.y.y,z,z,z,z I want to create output x.x.x.x x.x.x.y x.x...

Replacing string in textfile with quotes and doublequotes with sed

Hello, Lets say I want to replace the following string within a textfile: document.write(unescape("%3Cscript src='" + \ + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); I came up with this sed command, but surprisingly nothing happens at all. sed -i "s/document.write(unescape(\"%3Cscript src=\"\' + \\ + \"go...

How to read output of sed into a variable.

I have variable which has value "abcd.txt". I want to store everything before the ".txt" in a second variable, replacing the ".txt" with ".log" I have no problem echoing the desired value: a="abcd.txt" echo $a | sed 's/.txt/.log/' But how do I get the value "abcd.log" into the second variable? Thanks, Roger ...

sed+text on a specific line after an IP

I have the following line in my proftpd log (line 78 to be precise) Deny from 1.2.3.4 I also have a script which rolls through my logs for people using brute force attacks and then stores their IP (ready for a black listing). What i'm struggling with is inserting (presume with sed) at the end of that specific line - this is what I've ...

Using ANSI-C quoting in sed

Hello, I have a file named "insert.txt". It can look like this (or uglier): ASDFG?|??|?\/\HJKL<MNBVCXZQWERTYUIOP zxvbnmlkjhgfdsaqwertyuiop 123"'`~4567890987654321!@#$%^&*() @#$%^&*()+_}{":?> And I want to replace a block of text in a target file (target.txt) which is delimited by "STARTSTACKOVERFLOW" to "STOPSTACKOVERFLOW". (I am sim...

How to make sed read the script from script file?

Recently I came across following grep command: /usr/xpg4/bin/grep -Ff grep.txt input.txt > output.txt which as per my understanding means that from input.txt, grep the matter contained in grep.txt and output it to output.txt. I want to do something similar for sed i.e. I want to keep the sed commands in a separate file (say sed.txt) ...

print all rows following matched row

How can I print all rows after matching pattern in nth row, but ignore all before matched row including the matching row, here is an example : row1 something in this row row2 something in this row row3 something in this row row4 don't need to match the whole line, something like java String.contains() row5 something in this row row6 som...

Replacing a *specific* term in an XML file

I want to replace the text PATHTOEXPORT with the contents of a variable passed on the command-line that would have a folder path in it (for example, /Dev_Content/AIX/Apache) I came across this article that discusses how to use sed to replace a value in an XML file with another. However, not having used sed before, I'm unsure how to rea...

How to get only last IP from one or many divided by comma on beginning of the line

Hi, I would like to parse log files, I need to get only last IP from one or many divided by comma on beginning of the line: This is how the lines look like: 80.250.5.1 - - [26/Oct/2010:13:10:14 +0200] ... 80.250.5.1, 80.250.5.2 somethingA - [26/Oct/2010:13:10:14 +0200] ... 80.250.5.1, 80.250.5.2, 80.250.5.3 - somethingB [26/Oct/2010:1...

How to replace whitespace with one blank using sed?

Using sed "s/[[:blank:]]*/ /g" a>b doesn't seem to work. ...

How do you "debug" a regular expression with sed?

I'm trying to use a regexp using sed. I've tested my regex with kiki, a gnome application to test regexpd, and it works in kiki. date: 2010-10-29 14:46:33 -0200; author: 00000000000; state: Exp; lines: +5 -2; commitid: bvEcb00aPyqal6Uu; I want to replace author: 00000000000; with nothing. So, I created the regexp, that works when ...

delete html comment tags using regexp

Hi! This is how my text (html) file looks like <!-- | | | This is a dummy comment | | please delete me | | asap | | | ________________________________ | --> this is another line i...