Sponsored Content
Full Discussion: Replace patterns in a file
Top Forums Shell Programming and Scripting Replace patterns in a file Post 302596966 by isaacniu on Wednesday 8th of February 2012 09:41:54 PM
Old 02-08-2012
Quote:
Originally Posted by gary_w
In vi:
<ESC> (to go into command mode)
Code:
:%s/.log/.log.bz2/g

Using sed:
Code:
sed 's/.log/.log.bz2/' filename > filename.new

Hi Gary,

A sample of my entry is,
/logs/dvgbiau/batch/unit_test-20120131_000943.log

If I use sed 's/.log/.log.bz2/' filename > filename.new to make the replacement, it will become
.log.bz2s/dvgbiau/batch/unit_test-20120131_000943.log

However I'm expecting something like below?
/logs/dvgbiau/batch/unit_test-20120131_000943.log.bz2

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to replace certain patterns in a file thru unix!!

Hi Friends, well what i want to do is that suppose i have a file say like .... ronaldduckdancecoolman donaldmuckdancepooltactics fonaldguckdancetoolbutcomps .... okok i agree this is a ridiculous data for a file. :-) now i want that the characters in each line fromposition 16 to say 19... (6 Replies)
Discussion started by: mexx_freedom
6 Replies

2. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

3. UNIX for Dummies Questions & Answers

replace multiple patterns in a string/filename

This should be somewhat simple, but I need some help with this one. I have a bunch of files with tags on the end like so... Filename {tag1}.ext Filename2 {tag1} {tag2}.ext I want to hold in a variable just the filename with all the " {tag}" removed. The tag can be anything so I'm looking... (4 Replies)
Discussion started by: kerppz
4 Replies

4. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

Search and replace multiple patterns in a particular column only - efficient script

Hi Bigshots, I have a pattern file with two columns. I have another data file. If column 1 in the pattern file appears as the 4th column in the data file, I need to replace it (4th column of data file) with column 2 of the pattern file. If the pattern is found in any other column, it should not... (6 Replies)
Discussion started by: ss112233
6 Replies

6. Shell Programming and Scripting

Replace multiple patterns together with retaining the text in between

Hi Team I have the following text in one of the file j1738-abc-system_id(in.value1)-2838 G566-deF-system_id(in.value2)-7489 I want to remove system_id(...) combination completely The output should look like this j1738-abc-in.value1-2838 G566-deF-in.value2-7489 Any help is appreciated... (4 Replies)
Discussion started by: Thierry Henry
4 Replies

7. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

8. UNIX for Beginners Questions & Answers

awk Replace Multiple patterns within a list_file with One in target_file

I'm facing a problem 1) I got a list_file intended to be used for inlace replacement like this Replacement pattern ; Matching patterns EXTRACT ___________________ toto ; tutu | tata | tonton | titi bobo ; bibi | baba | bubu | bebe etc. 14000 lines !!! ... (5 Replies)
Discussion started by: mpvphd
5 Replies

9. Shell Programming and Scripting

Sed, how replace specific symbols between two patterns

I have a big xmltv file with many lines like: <?xml version="1.0" encoding="UTF-8"?> <tv> <channel id="channel 1 +3HD"> <display-name lang="it">channel +3HD</display-name> <icon src="http://mywebsite.com/dsgbnjfdc65657/channel +3HD.png" /> ... (8 Replies)
Discussion started by: Tapiocapioca
8 Replies

10. UNIX for Beginners Questions & Answers

Grep multiple patterns(file) and replace whole line

I am able to grep multiple patterns which stored in a files. However, how could we replace the whole line with either the pattern or new string? For example: pattern_file: *Info in the () is not part of the pattern file. They are the intended name to replace the whole line after the pattern... (5 Replies)
Discussion started by: wxboo
5 Replies
FSCK-LARCH(1)						      General Commands Manual						     FSCK-LARCH(1)

NAME
fsck-larch - verify that a larch B-tree is internally consistent SYNOPSIS
fsck-larch [--config=FILE] [--dump-config] [--dump-memory-profile=METHOD] [--dump-setting-names] [--fix] [--generate-manpage=TEMPLATE] [-h] [--help] [--list-config-files] [--log=FILE] [--log-keep=N] [--log-level=LEVEL] [--log-max=SIZE] [--log-mode=MODE] [--no-default-configs] [--output=FILE] [--trace=PATTERN] [--version] [FILE]... DESCRIPTION
fsck-larch reads an on-disk, committed B-tree created by the larch Python library, and verifies that it is internally consistent. It re- ports any problems it finds, but does not currently fix them. OPTIONS
--config=FILE add FILE to config files --dump-config write out the entire current configuration --dump-memory-profile=METHOD make memory profiling dumps using METHOD, which is one of: none, simple, meliae, or heapy (default: simple) --dump-setting-names write out all names of settings and quit --fix fix problems found? --generate-manpage=TEMPLATE fill in manual page TEMPLATE -h, --help show this help message and exit --list-config-files list all possible config files --log=FILE write log entries to FILE (default is to not write log files at all); use "syslog" to log to system log, or "none" to disable log- ging --log-keep=N keep last N logs (10) --log-level=LEVEL log at LEVEL, one of debug, info, warning, error, critical, fatal (default: debug) --log-max=SIZE rotate logs larger than SIZE, zero for never (default: 0) --log-mode=MODE set permissions of new log files to MODE (octal; default 0600) --no-default-configs clear list of configuration files to read --output=FILE write output to FILE, instead of standard output --trace=PATTERN add PATTERN to trace patterns --version show program's version number and exit SEE ALSO
Larch home page (http://liw.fi/larch/). FSCK-LARCH(1)
All times are GMT -4. The time now is 04:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy