2
votes
2answers
32 views

Sed find and replace with slashes

I am having trouble using sed find/replace with slashes in the find parameter. Sample contents of test.sh str=$(sed -n '/^user:/p' /tmp/shadowtest) # find "user:" line in /etc/shadowtest ...
1
vote
1answer
115 views

Pattern replacement

Please can anyone explain to me in brief the syntax of this command. Explanation in terms of how actually this command is written significance of each and every character used. I know the output of ...
1
vote
2answers
67 views

List all the html tags in a file

I want to know if there is a way to list all the html tags in a file. Lets say I have a file file.html <html> <head> <title>Test</title> </head> <body> This is a ...
1
vote
1answer
44 views

Delete a matching line in a file doesn't work

So, I have this piece of a code: while read line do if [ $line = $maddr ] ; then sed -i '/${maddr}/d' mailinglist found=true ...
1
vote
2answers
74 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) ...
-2
votes
1answer
66 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
1
vote
3answers
64 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 ...
4
votes
4answers
474 views

Bash Scripting : Printing column data in the same row

I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows: ...
0
votes
2answers
253 views

Using grep to find first two numbers of IP addresses?

I'm trying to figure out how to use grep to pull out only the first two numbers of an IP address in a list. I've got a routine that is isolating the log entires (from Exim) that I need, now I just ...
2
votes
2answers
123 views

stripping out the last two [end] with sed?

I'm working on a script that improves the fluxbox 'menu', and my script has this line: sed -i 's/\[end]//g' ~/.fluxbox/menu;sed -i '/^\s*$/d' ~/.fluxbox/menu but this has the unfortunate effect of ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
2
votes
2answers
145 views

Sanitize Apache access log files?

We have this code in a shell script that pipes output for Apache to log. declare -a values=( $taintRequestVals ) for item in ${!values[@]} do cat $apacheLog | sed ...
2
votes
3answers
99 views

Using sed to insert latex commands around headers of a document

I have a documen with headers in ALL CAPS, for example: NAME env - run a program in a modified environment and I want to insert \item[ before the header and ] \hfill \\ after a header ...
3
votes
1answer
153 views

How can I write a sed script to delete numbers from a line?

Sample File a.b.gg3d 0000000001 0000000001 y a.b.112a 0000000000 0000000001 y a.b.gg3s 0000000001 0000000001 y a.b.1111 0000000000 0000000001 m I have a file that includes about three thousand ...
1
vote
2answers
176 views

Why the inconsistency with using cat vs. echo piped to this sed command?

Inspired by this question: sed: N command does not read single line I wanted to understand why there appears to be an inconsistency between the following 2 commands: #1. echo This command produces ...
0
votes
2answers
394 views

sed - replace complex lines in a file using variables

How do I replace a complex line in a file using sed? For example I want replace a udev rule in /etc/udev/rules.d/70-persistent-net.rules. This doesn't work: OLD_RULE='SUBSYSTEM=="net", ...
2
votes
2answers
416 views

Add a suffix string to end of each line? [duplicate]

I have two files: file01: line1 line2 line3 file02: A B C And I want to get line1 A line2 B line3 C I could possibly write a Perl script but it is better if I don't need to. I have tried ...
2
votes
3answers
2k views

sed - how to replace a single quote?

This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click ...
3
votes
3answers
1k views

How to share a GNU sed script between Linux and Mac OS X

I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
6
votes
4answers
2k views

How to remove multiple blank lines from a file?

I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
3
votes
1answer
58 views

How to edit files in-place while performing operation on the values matching the searched pattern?

Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ? Ideally a solution ...
1
vote
2answers
358 views

How can I find matches with sed (or similar) for configuration parameters?

I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed. I have two shell scripts I'm working on and I'd ...
1
vote
2answers
123 views

How to parse fields out of a text file and write them to another file

I have executed a database command and have generated an output file of the results. Each field name starts with dbt_xxxxxx Each field value is the value after the equal sign. how can I parse the file ...
2
votes
2answers
3k views

Sed: replacing digits

I am trying to write some install scripts for when I install/upgrade Ubuntu. I'm having trouble with fixing logrotate.d: /var/log/ufw.log { rotate 7 weekly missingok notifempty compress delaycompress ...
5
votes
4answers
2k views

How to perform a sed in-place substitution that only creates backups of files that were changed?

I ran the following to replace a term used in all files in the current working directory: $ find . -type f -print0 | xargs -0 sed -i'.bup' -e's/Ms. Johnson/Mrs. Melbin/g' This performed the word ...
2
votes
1answer
569 views

How do I replace certain text with the respective line number using sed?

I have a file where certain (not all) lines look like so: Sequence: n I wish to replace n with the respective line number. How can I do it with sed?
5
votes
3answers
3k views

The way to use `/usr/bin/env sed -f ` in shebang?

Typing /usr/bin/env sed -f in terminal works. But if use it as a shebang, #!/usr/bin/env sed -f s/a/b/ The script will be fail to execute: /usr/bin/env: sed -f: No such file or directory I ...
3
votes
4answers
1k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
5
votes
4answers
8k views

Processing bash variable with sed

Been banging my head off a wall on this bash variable LATLNG contains a latitude & longitude value in brackets like so (53.3096,-6.28396) I want to parse these into a variable called LAT and ...
5
votes
1answer
2k views

Replacing multiple lines in sed or awk

I'm trying to use sed or awk to replace 5 lines in a smb file but I just don't have any idea how to deal with the newlines.
8
votes
4answers
7k views

grep — removing text after delimiter token

I have a file in which I need to eliminate everything after the first ; on every line. So a file like this: sdfsdsdf; fsdfsddf;sdfsd; Will result in this: sdfsdsdf fsdfsddf I have looked into ...