Sponsored Content
Top Forums Shell Programming and Scripting Gnu tool; sed awk echo etc to prepend or append string to a file Post 302992316 by bash_in_my_head on Thursday 23rd of February 2017 04:19:39 PM
Old 02-23-2017
Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example

File example;
Code:
nodegroups:
  check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com

I need to take a file with a one line list of hosts separated by commas

Code:
host.domain.com,host2.domain.com,host3.domain.com

and prepend the string " check-hosts: L@" to the line of hosts above (line 2). I need to have two spaces before "check-hosts: L@"
My approach has been to prepend the string " check-hosts: L@" to the file containing the line of hosts. but I am open to other ways as long as I can use the file that contains a list of hosts as the starting poing.

Line 1 nodegroups: needs to be above line 2 in my example.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

echo, append to end of file

I need the line printed with echo to append to eof of to exactly line, am i able to do that? i mean echo "sysctl -w lalala=1" > to end of file /etc/sysctl.conf or to the 21st line, if the line exist, open new line and insert text there. Thx.maybe i'm in wrong topic but anyway... (2 Replies)
Discussion started by: hachik
2 Replies

2. Shell Programming and Scripting

Append and Prepend Text to a file list

I want to print out a directory listing, then append ] to the end of each line. I'm trying to create a list of Wiki links based on folder listings that i can just copy and paste without having to edit 100's of file listings. Using sed i've figured out to do something like this: sed... (4 Replies)
Discussion started by: CapnDoody
4 Replies

3. Shell Programming and Scripting

prepend and append characters to the same line

Hi, I have a file 'tmp.dat' that contains the below data: 81763 40829 30405 80452 I want to prepend a ' character to the beginning of every line, and I want to append ', at the end of every line. Below is what I expect: '81763', '40829', '30405', '80452', Can anyone help me? ... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

4. Shell Programming and Scripting

sed append to string

I am trying to replace in multiple files every instance of text that begins with http and add hyperlink characters to it. I can get it to work with the following:sed -e "s/http*.*/<a href=\"&\">&<\/a>/g" * as long as the http text is at the end of the file. I need it to stop at the end of the... (2 Replies)
Discussion started by: numele
2 Replies

5. Shell Programming and Scripting

sed to find first appearance and append string

I have a file like below #GROUP A belongs to Asia GROUP A jojh hans local admin GROUP A gege fans michel jing jong #GROUP U belongs to USA GROUP U jeff goal hello world My requirement is to grep for first apperence of GROUP A which is not commented and append my name to end of file.... (12 Replies)
Discussion started by: vkk
12 Replies

6. Shell Programming and Scripting

perform echo and awk inside a string

hi, just wanted to make a shortcut of this one a="a b c" b=`echo $a | awk '{print $2}'` echo "the middle is $b" why can't i do this: a="a b c" echo "the middle is ${`echo $a | awk '{print $2}'`}" <- bad substitution :wall: thanks (6 Replies)
Discussion started by: h0ujun
6 Replies

7. Shell Programming and Scripting

Append a searched string with another string using sed

Hi, I need to replace and append a string in a text if grep is true. For eg: grep ABC test.txt | grep -v '\.$' | awk {'print $4'} | sed "s/ ? How do I replace all instances of "print $4" using sed with another sring? Eg of the string returned will be, lx123 web222 xyz Want to... (8 Replies)
Discussion started by: vchee
8 Replies

8. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
MKNETID(8)						    BSD System Manager's Manual 						MKNETID(8)

NAME
mknetid -- a NIS filter program SYNOPSIS
mknetid [-q] [-d domain] [-p passwdfile] [-g groupfile] [-h hostfile] [-m netidfile] DESCRIPTION
mknetid is used to create a map named netid.byname. The map consists of information from passwd(5), group(5) and hosts(5) eventually con- catenated with a netid(5) file. The options are as follows: -d domain NIS domain to use instead of the default domain. -g groupfile Alternate group(5) file. Default is /etc/group. -h hostfile Alternate hosts(5) file. Default is /etc/hosts. -m netidfile Alternate netid(5) file. Default is /etc/netid. -p passwdfile Alternate passwd(5) file. Default is /etc/passwd. -q Keep quiet about multiple occurrences of a uid; ignore all but the first. FILES
/etc/group /etc/hosts /etc/netid /etc/passwd SEE ALSO
domainname(1), group(5), hosts(5), netid(5), passwd(5), nis(8) AUTHORS
Mats O Jansson <moj@stacken.kth.se> BSD
February 26, 2005 BSD
All times are GMT -4. The time now is 10:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy