Sponsored Content
Top Forums Shell Programming and Scripting sed - Replace Line which contains the Pattern match with a new line Post 302112000 by cfajohnson on Saturday 24th of March 2007 12:10:15 AM
Old 03-24-2007
Quote:
Originally Posted by kousikan
I need to replace the line containing "STAGE_DB" with the line
"STAGE_DB $DB # database that contains the table being loaded ($workingDB)"

Here $DB is passed during the runtime.

Code:
sed "s/STAGE_DB/STAGE_DB    $DB    # database that contains the table being loaded ($workingDB)/" FILE > tempfile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed scripting, match text within line and replace

New to sed... Have a file foo.txt (below). Need to replace text on 2 lines, but can only feed sed the first few characters of each line (all lines are unique). So, in my example, I have put '$' in place of what I need to figure out how to feed the whole line. What I have thus far: sed -e... (6 Replies)
Discussion started by: boolean2222
6 Replies

2. Shell Programming and Scripting

search pattern and replace x-y characters in nth line after every match

Hi, I am looking for any script which can do the following. have to read a pattern from fileA and copy it to fileB. fileA: ... ... Header ... ... ..p1 ... ... fileB: .... .... Header (3 Replies)
Discussion started by: anilvk
3 Replies

3. Shell Programming and Scripting

pattern match and replace another pattern in same line

I have a pattern username:x:32005:32006::/usr/local/user:/bin/bash I need to match the line containing username and replace /bin/bash with /usr/local/my/bin/noshell So it becomes username:x:32005:32006::/usr/local/user:/usr/local/my/bin/noshell (7 Replies)
Discussion started by: anilcliff
7 Replies

4. Shell Programming and Scripting

Help with replace line based on specific pattern match

Input file data20714 7327 7366 detail data20714 7327 7366 main data250821 56532 57634 detail data250821 57527 57634 main data250821 57359 57474 main data250821 57212 57301 main data250821 57140 57159 detail data250821 56834 57082 main data250821 56708 56779 main ... (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

Replace everything but pattern in a line using sed

I have a file with multiple lines like this: <junk><PATTERN><junk><PATTERN><junk> <junk><PATTERN><junk><PATTERN><junk><PATTERN><junk> Note that 1. There might be variable number occurrences of PATTERN in a line. 2. <> are just placeholders, they do not form part of the pattern. I need... (4 Replies)
Discussion started by: flatley
4 Replies

6. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

7. Shell Programming and Scripting

Sed replace using same pattern repeating multiple times in a line

Sed replace using same pattern repeating multiple times in a line I have text like below in a file: I am trying to replace the above line to following How can I acheive this? I am able to do it if the occurrence is for 1 time: But If I try like below I am getting like this: I have to... (4 Replies)
Discussion started by: sol_nov
4 Replies

8. Shell Programming and Scripting

Awk-sed help : to remove first and last line with pattern match:

awk , sed Experts, I want to remove first and last line after pattern match "vg" : I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data. - So it should check for the pattern vg if present , then it should delete the line ,... (5 Replies)
Discussion started by: rveri
5 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies
UNCRUSTIFY(1)							   User Commands						     UNCRUSTIFY(1)

NAME
uncrustify - C, C++, C#, D, Java and Pawn source code beautifier SYNOPSIS
uncrustify [OPTIONS] [FILES] DESCRIPTION
If no input files are specified, the input is read from stdin. If reading from stdin, you should specify the language using -l. If -F is used or files are specified on the command line, the output filename is PFX + "/" + filename + SFX. Unless, of course, the options --replace or --no-backup are used. When reading from stdin or doing a single file via the '-f' option, the output is dumped to stdout, unless redirected with -o FILE. Errors are always dumped to stderr OPTIONS
Basic Options: -c CFG Use the config file CFG. If not specified, uncrustify will use $UNCRUSTIFY_CONFIG or $HOME.uncrustify.cfg. -f FILE Process the single file FILE, sending output to stdout or the file specified with -o. -o FILE Redirect output to FILE. Use with -f, --update-config, --update-config-with-doc, --universalindent. -F FILE Read files to process from FILE, one filename per line. You can create this file using something like 'find . -name "*.c" > list.txt'. This cannot be combined with -f. --prefix PFX Prepend PFX to the output filename path. This cannot be combined with -f, --replace, or --no-backup. --suffix SFX Append SFX to the output filename. The default is '.uncrustify' if neither SFX or PFX are specified. This cannot be combined with -f, --replace, or --no-backup. --frag Assume the input is a code fragment and the first line is properly indented. --replace Replace source files (creates a backup). This cannot be combined with -f, --prefix, or --suffix. --no-backup Replace files, no backup. Useful if files are under source control This cannot be combined with -f, --prefix, or --suffix. --mtime Preserve mtime on replaced files. -l Language override: C, CPP, D, CS, JAVA, PAWN, VALA, OC, OC+ -t Load a file with types (usually not needed) -q Quiet mode - no output on stderr (-L will override) Config/Help Options: -h -? --help --usage Print this message and exit --version Print the version and exit --show-config Print out option documentation and exit --update-config Output a new config file. --update-config-with-doc Output a new config file with embedded usage comments. --universalindent Output a config file for Universal Indent GUI. --detect Detects the config from a source file. Use with '-f FILE'. Detection is currently fairly limited. Debug Options: -p FILE Dump debug info to a file -L SEV Set the log severity (see log_levels.h) -s Show the log severity in the logs --decode FLAG Print FLAG as text and exit EXAMPLES
Read a D file from stdin, output to stdout. cat foo.d | uncrustify -q -c my.cfg -l d Process a file, output to stdout. uncrustify -c my.cfg -d foo.d Process a source tree, output to a different tree. find src -name "*.[ch]" > files.txt uncrustify -c my.cfg -F files.txt --prefix out Process a source tree in-place. uncrustify -c my.cfg --no-backup $(find src -name "*.[ch]") NOTES
Use comments containing ' *INDENT-OFF*' and ' *INDENT-ON*' to disable processing of parts of the source file. AUTHOR
Written by Ben Gardner REPORTING BUGS
Use the issue tracker at <http://sourceforge.net/projects/uncrustify> COPYRIGHT
Copyright (C) 2006-2009 Ben Gardner LICENSE
GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. uncrustify 0.59 Oct 2009 UNCRUSTIFY(1)
All times are GMT -4. The time now is 05:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy