Sponsored Content
Top Forums Shell Programming and Scripting How to print & and \n while replacing with sed/awk? Post 302997441 by RudiC on Saturday 13th of May 2017 10:43:34 AM
Old 05-13-2017
1) excape the & with a backslash, and escape the \n's backslash as well
2) use single quote to prevent expansion by the shell
Code:
string='din\&esh\\nisgood'
sed "s#\[Name\]#${string}#g" file
the name is din&esh\nisgood

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies

2. Shell Programming and Scripting

awk pipes & print

Hi, I need to awk some data from some text files, basic stuff, eg: awk '/phrase/ {print $1,$2,$3}' file Which will print columns 1 to 3 of all lines containing "phrase" But what if I wanted to pipe just one of the columns to a command (in my case a date converter) as in: awk... (4 Replies)
Discussion started by: Jonny2Vests
4 Replies

3. Shell Programming and Scripting

Replacing or removing a long list of pattern by using awk or sed

Input: >abc|123456|def|EXIT| >abc|203456|def|EXIT2| >abc|234056|def|EXIT3| >abc|340056|def|EXIT4| >abc|456000|def|EXIT5| . . . Output: def|EXIT| def|EXIT2| def|EXIT3| def|EXIT4| def|EXIT5| . . My try code: (9 Replies)
Discussion started by: patrick87
9 Replies

4. Shell Programming and Scripting

AWK - Pattern Matching & Replacing - Performance

Experts, I am a beginner to Unix Shell Scripting We have source as a flat file which contains CTRL+F character as the delimiter. We need to count the number of records in the file (CTRL+F) to perform file validation Following command being used: awk '{cnt+=gsub(//,"&")}END {print cnt}'... (4 Replies)
Discussion started by: srivijay81
4 Replies

5. Shell Programming and Scripting

awk: Multiple search patterns & print in an one liner

I would like to print result of multiple search pattern invoked from an one liner. The code looks like this but won't work gawk -F '{{if ($0 ~ /pattern1/) pat1=$1 && if ($0 ~ /pattern2/) pat2=$2} ; print pat1, pat2}' Can anybody help getting the right code? (10 Replies)
Discussion started by: sdf
10 Replies

6. Shell Programming and Scripting

Replacing FQDN by hostnames in a CSV file with sed & awk

Hello, Beginning with shell scipting, I'm trying to find in a csv file, the lines where the field related to hostname is displayed as an FQDN intead the hostname. (some lines are correct) and the to correct that inside the file: Novell,11.0,UNIX Server,bscpsiws02,TxffnX1tX1HiDoyBerrzWA==... (2 Replies)
Discussion started by: Wonto
2 Replies

7. Shell Programming and Scripting

awk Help: Filter Multiple Entry & print in one line.

AWK Gurus, data: srvhcm01 AZSCI srvhcm01 AZSDB srvhcm01 BZSDB srvhcm01 E2QDI31 srvhcm01 YPDCI srvhcm01 YPDDB srvhcm01 UV2FSCR srvhcm01 UV2FSBI srvhcm01 UV2FSXI srvhcm01 UV2FSUC srvhcm01 UV2FSEP srvhcm01 UV2FSRE srvhcm01 NASCI srvhcm01 NASDB srvhcm01 UV2FSSL srvhcm01 UV2FSDI (7 Replies)
Discussion started by: rveri
7 Replies

8. Shell Programming and Scripting

awk question: How to print condition of NR & NF together.

Experts: LINE1 :This is line one The FIRST line of the file. LINE2 :This is line two LINE3 :This is line three with 8 fileds LINE4 :This is line four LINE5 :This is line five LINE6 :This is line six with 8 fileds I want to delete line 1, and then process the file and want to print lines... (2 Replies)
Discussion started by: rveri
2 Replies

9. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

10. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies
OPENPAM_READWORD(3)					   BSD Library Functions Manual 				       OPENPAM_READWORD(3)

NAME
openpam_readword -- read a word from a file, respecting shell quoting rules LIBRARY
Pluggable Authentication Module Library (libpam, -lpam) SYNOPSIS
#include <sys/types.h> #include <stdio.h> #include <security/pam_appl.h> #include <security/openpam.h> char * openpam_readword(FILE *f, int *lineno, size_t *lenp); DESCRIPTION
The openpam_readword() function reads the next word from a file, and returns it in a NUL-terminated buffer allocated with malloc(3). A word is a sequence of non-whitespace characters. However, whitespace characters can be included in a word if quoted or escaped according to the following rules: o An unescaped single or double quote introduces a quoted string, which ends when the same quote character is encountered a second time. The quotes themselves are stripped. o Within a single- or double-quoted string, all whitespace characters, including the newline character, are preserved as-is. o Outside a quoted string, a backslash escapes the next character, which is preserved as-is, unless that character is a newline, in which case it is discarded and reading continues at the beginning of the next line as if the backslash and newline had not been there. In all cases, the backslash itself is discarded. o Within a single-quoted string, double quotes and backslashes are preserved as-is. o Within a double-quoted string, a single quote is preserved as-is, and a backslash is preserved as-is unless used to escape a double quote. In addition, if the first non-whitespace character on the line is a hash character (#), the rest of the line is discarded. If a hash charac- ter occurs within a word, however, it is preserved as-is. A backslash at the end of a comment does cause line continuation. If lineno is not NULL, the integer variable it points to is incremented every time a quoted or escaped newline character is read. If lenp is not NULL, the length of the word (after quotes and backslashes have been removed) is stored in the variable it points to. RETURN VALUES
If successful, the openpam_readword() function returns a pointer to a dynamically allocated NUL-terminated string containing the first word encountered on the line. The caller is responsible for releasing the returned buffer by passing it to free(3). If openpam_readword() reaches the end of the line or file before any characters are copied to the word, it returns NULL. In the former case, the newline is pushed back to the file. If openpam_readword() reaches the end of the file while a quote or backslash escape is in effect, it sets errno to EINVAL and returns NULL. IMPLEMENTATION NOTES
The parsing rules are intended to be equivalent to the normal POSIX shell quoting rules. Any discrepancy is a bug and should be reported to the author along with sample input that can be used to reproduce the error. SEE ALSO
openpam_readline(3), openpam_readlinev(3), pam(3) STANDARDS
The openpam_readword() function is an OpenPAM extension. AUTHORS
The openpam_readword() function and this manual page were developed by Dag-Erling Smorgrav <des@des.no>. BSD
September 12, 2014 BSD
All times are GMT -4. The time now is 06:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy