Sponsored Content
Full Discussion: sed to add a line to a file
Top Forums Shell Programming and Scripting sed to add a line to a file Post 303018671 by giri_luck on Wednesday 13th of June 2018 01:38:59 AM
Old 06-13-2018
sed to add a line to a file

Hi,

I am trying to add a line to a file using sed.

tmp1:
Code:
aaaa
Hello
bbbb
Hello

I need to add "testing" after the first match of Hello. So the output should be

Code:
aaaa
Hello
testing
bbbb
Hello

and the line to be added will be a variable

using command line this works:

Code:
echo $line
testing

cat tmp1 | sed '1,/Hello/ {/Hello/a\
'$line'
}'

but the same if i execute using a script it fails with error,
Code:
sed: -e expression #1, char 68: unknown command: `-'


Moderator's Comments:
Mod Comment Please use CODE tags - for data as well - as required by forum rules!

Last edited by RudiC; 06-13-2018 at 05:49 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

add new line using SED

Hi, I want to add two new lines to a file. I have: dn: uid=beele,ou=medewerker,dc=hva,dc=nl street: Wibautstraat 2-4 dn: uid=beelx,ou=medewerker,dc=hva,dc=nl street: Wibautstraat 2-4 I want to make: dn: uid=beele,ou=medewerker,dc=hva,dc=nl changetype: modify replace: street street:... (3 Replies)
Discussion started by: tine
3 Replies

2. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies

3. Shell Programming and Scripting

Need to add new line using sed

I need to add a new line using sed based on matching a pattern. I need to add the blank line after the line that I am matching on. Any help? (1 Reply)
Discussion started by: scrappycc
1 Replies

4. Shell Programming and Scripting

sed to add a new line

Hi In my sed version the interactive method of adding a new works : > sed '3a\ new line ' file_name But i want to do the same task in one command as it is a part of a script. i hav tried the following but no luck so far cat file_name |sed -e '3a\ new line ' cat file_name |sed -e... (4 Replies)
Discussion started by: ningy
4 Replies

5. Shell Programming and Scripting

sed add after line x new text from file

I've been playing with sed, trying to get it to insert the contents of somefile.txt after line 13 on anotherfile.txt. I tried searching for a line with regex and attempting to insert something on the next line with: find ./anotherfile.txt -type f -exec sed -i -e '/^dog/cat/' {} \; but it... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shell Programming and Scripting

sed to add text in new line

help i need to add a "nfsd" in new line after cron ex: cron rpcbind output: cron nfsd rpcbind i use sed -e "/cron/G; s/$/nfsd/" myfile output: cron nfsd rpcbindnfsd (5 Replies)
Discussion started by: jamilzain
5 Replies

7. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

8. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

9. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

10. Shell Programming and Scripting

sed add line to config file

what is the sed command line to add a line to a config file config file name is "config" line to be added cpuid.7.edx = "----:00--:----:----:----:----:----:----" thanks (4 Replies)
Discussion started by: tdubb123
4 Replies
IRSEND(1)							   User Commands							 IRSEND(1)

NAME
irsend - basic LIRC program to send infra-red commands SYNOPSIS
irsend [options] DIRECTIVE REMOTE CODE [CODE...] DESCRIPTION
Asks the lircd daemon to send one or more CIR (Consumer Infra-Red) commands. This is intended for remote control of electronic devices such as TV boxes, HiFi sets, etc. DIRECTIVE can be: SEND_ONCE - send CODE [CODE ...] once SEND_START - start repeating CODE SEND_STOP - stop repeating CODE LIST - list configured remote items SET_TRANSMITTERS - set transmitters NUM [NUM ...] SIMULATE - simulate IR event REMOTE is the name of a remote, as described in the lircd configuration file. CODE is the name of a remote control key of REMOTE, as it appears in the lircd configuration file. NUM is the transmitter number of the hardware device. For the LIST DIRECTIVE, REMOTE and/or CODE can be empty: LIST "" "" - list all configured remote names LIST REMOTE "" - list all codes of REMOTE LIST REMOTE CODE - list only CODE of REMOTE The SIMULATE command only works if it has been explicitly enabled in lircd. -h --help display usage summary -v --version display version -d --device use given lircd socket [/var/run/lirc/lircd] -a --address=host[:port] connect to lircd at this address -# --count=n send command n times EXAMPLES
irsend LIST DenonTuner "" irsend SEND_ONCE DenonTuner PROG-SCAN irsend SEND_ONCE OnkyoAmpli VOL-UP VOL-UP VOL-UP VOL-UP irsend SEND_START OnkyoAmpli VOL-DOWN ; sleep 3 irsend SEND_STOP OnkyoAmpli VOL-DOWN irsend SET_TRANSMITTERS 1 irsend SET_TRANSMITTERS 1 3 4 irsend SIMULATE "0000000000000476 00 OK TECHNISAT_ST3004S" FILES
/etc/lirc/lircd.conf Default lircd configuration file. It should contain all the remotes, their infra-red codes and the corresponding timing and wave- form details. DIAGNOSTICS
If lircd is not running (or /var/run/lirc/lircd lacks write permissions) irsend aborts with the following diagnostics: "irsend: could not connect to socket" "irsend: Connection refused" (or "Permission denied"). SEE ALSO
The documentation for lirc is maintained as html pages. They are located under html/ in the documentation directory. lircd(8), mode2(1), smode2(1), xmode2(1), irrecord(1), irw(1), http://www.lirc.org. irsend 0.9.0-pre1 October 2010 IRSEND(1)
All times are GMT -4. The time now is 06:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy