I will have a look at the first piece of code you gave me and see what the affect is.
I think i got the -e option of sed now, thanks also.
The 's/findstr/repstring/g' is about the most common syntax of sed i can actually understand.
which is why i hate why i cant understand a simple thing like append.
I understand it appends a line after the line in which a pattern is found.
I also understand the i option which inserts a string before the line in which a pattern is found.
Is what i say right?
Almost. Yes, the sed a command appends one or more lines of text starting on the line after the addressed line. No, the sed i command (not option) does not insert a string at the start of a line; it inserts one or more lines of text before an addressed line.
Quote:
Anyhow, what i am trying to say what i want which is "appending" text to a same line in which a pattern is found is obviously not being correctly asked so i apologize,
Nothing that you have described involves appending LINES of text nor inserting LINES of text. Nothing that you have described can be done with a sed a or i command because you DO NOT want to create new lines of text, you only want to add strings of text to existing lines of text, delete strings of text from existing lines of text, or modify strings of text on existing lines of text. All three of these are done with the sed s command, i.e., commands of the form that you said you already understand:
which would more correctly be written as:
where BRE is a basic regular expression (which in its simplest form could just be a string of regular characters, but could also be an extremely complex expression matching repeated complex patterns); replacement could be a simple string of zero or more regular characters or could include meta-characters that refer to selected portions of the text matched by the BRE; and flags (including, but not limited to, the frequently over-used g flag). And, even in that simple form, the / characters separating the command name (s), the BRE, the replacement, and the flags can be replaced by almost any other character (except the <newline> character) which can be useful when the BRE or the replacement contain <slash> characters.
Quote:
Let me test the affects of the first code example you gave me and see if i get it, thanks.
Moderator's Comments:
Please use CODE and ICODE tags when displaying sample input, sample output, and code segments (as required by forum rules). Using tags is helpful when displaying text to help determine whether you are talking about generic, descriptive text versus explicit exact text to be added, matched, removed, ... When the different between a single <space> versus one or more <space> and/or <tab> characters matters, CODE or ICODE tags are crucial. Use CODE tags when displaying one or more complete lines of sample input, sample output, or code. Use ICODE tags when displaying partial lines of sample input, sample output, or code.
Note also that the sed s command, the ed s command, the ex s command, the vi :s command, and the awk sub() and gsub() functions all behave very similarly (although the awk sub() and gsub() functions use extended REs (EREs) instead of the BREs used by sed, ed, ex, and vi.
Hi everyone
I just need a script that should just search for a particular keyword in a line and after that it should add some text to the next line.
I have tried it in HAMILTON CSHELL using
sed "hello/a\newtext" file.txt
But it give me message
sed: "\" must terminate the "a"... (4 Replies)
Hi all
I tried this on an old version of sed on NCR Unix MP-RAS:
sed -e "s/$/nnn/" file1 >file2
This file (file1):
the cat sat on the mat.
the cat sat on the mat.
the cat sat on the mat.
becomes this (file2):
the cat sat on the mat.nnn
the cat sat on the mat.nnn
nnn
the... (3 Replies)
Hi All
I'm trying to insert a pattern if a pattern is found in a file.
This is my sample file
"PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|25
"PDA"|"Celvin"|"PRJ_AB"|"Completion_Units"|250
I would like to output as
"PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|"Done"|25... (3 Replies)
Input:
gstreamer-plugins-good
gstreamer-plugins-bad
gstreamer-plugins-ugly
Output should be:
gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly
How can it be done with sed? (5 Replies)
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)
After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh.
Now I've gotten the sed... (2 Replies)
im trying to append to the end of the line using sed but I want to do it without creating a new line
the text to which I want to append is all in capital letters.
I want to do something like this:
LINE]Foo
but when I do this:
//a\
] Foo
it prints foo on a new line:
LINE
]Foo
... (11 Replies)
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)
Hi, I posted in another section, but no reply yet.
I have an ini file with sections denoted as follows (for example)
blah=blah
blee=blee
bloo=bloo
blur=blur
blaa=blaa
I have ksh script that needs to append a line ${line} to the end of section ${section}
I saw this... (7 Replies)
Hello.
I have a config file (/etc/my_config_file) which may content :
#
# port for HTTP (descriptions, SOAP, media transfer) traffic
port=8200
# network interfaces to serve, comma delimited
network_interface=eth0
# set this to the directory you want scanned.
# * if have multiple... (6 Replies)