replacing letters in a word at his reverse sed [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I need to write script in sed that
The program prints the contents of the output file one after replacing all the old word
Three letters of the file - its first in reverse. (1 file contents remains unchanged after
Program)
example:
File F1:
hell hi uri ronit dani
abc def ab abcd
123456 123ab
after this command P8.3 F1 Received the following output:
hell hi iru ronit dani
cba fed ab abcd
123456 123ab
thanks

sed 's/\(\b\)\(\w\)\(\w\)\(\w\)\(\b\)/\1\4\3\2\5/g' input_file

Related

Windows Batch - delete last characters from variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I need to delete the last 3 characters from a variable in Windows batch
set string=abcdefghij
I need the following output:
abcdefg
I can delete the first 3 characters from the variable using this:
set newstring=%string:~3,100%
echo %newstring%
Output:
defghij
But how can I delete the last 3 characters from the string - and store the result into a variable?
I can show the string without the last 3 characters by using sed (from GnuWin32) but I also need to store the result into another variable. I need a better solution than storing the result in a file and then reading the file into a variable (set /p newstring=<file.txt)
Later note: This question is very different, it needs removing last characters from a multi-line text, while I need removing last characters from a variable.
Just use negative index
set longtext=1234567890
:: Remove last 3 characters
echo %longtext:~0,-3%
:: show last three characters
echo %longtext:~-3%
Output:
1234567
890

Substringing with bash [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to substring many strings with bash.However, despite the prefix is sorrectly deleted, the suffix is not.
One of the strings:
lcl|MK087647.1_cds_QHD46953.1_7_[gene=rpl2]_[protein=ribosomal_protein_L2]_[exception=RNA_editing]_[protein_id=QHD46953.1]_[location=complement(71768..73444)]_[gbkey=CDS]
The desired output:
MK087647.1_cds_QHD46953.1_7_[gene=rpl2]_[protein=ribosomal_protein_L2]
The code
for row in $colonna2; do tmp=${row#*lcl|}
colonna2_newname=${tmp%exception=*} echo $colonna2_newname; done
The output
MK087647.1_cds_QHD46953.1_7_[gene=rpl2]_[protein=ribosomal_protein_L2]_[exception=RNA_editing]_[protein_id=QHD46953.1]_[location=complement(71768..73444)]_[gbkey=CDS]
Any guess why the suffix is not deleted? Has my syntax some error?
Thanks in advance
You have the variable substitution mostly right; it seems the main problem with the code is that there is no line break or semicolon after you define the colonna2_newname variable.
You will also want to change the colonna2_newname variable's definition from ${tmp%exception=*} to ${tmp%_[exception=*}.
for row in $colonna2
do
tmp="${row#*lcl|}"
colonna2_newname="${tmp%exception=*}"
echo "$colonna2_newname"
done
# output:
# MK087647.1_cds_QHD46953.1_7_[gene=rpl2]_[protein=ribosomal_protein_L2]
Now about the for loop: If any of the lines in your $colonna2 variable have whitespace in them, for will split the line into separate strings after each space. for loops are better suited for use with arrays and globbed filenames/pathnames. while read loops are better to use with lines of text:
while IFS=$'\n' read -r row
do
tmp="${row#*lcl|}"
colonna2_newname="${tmp%exception=*}"
echo "$colonna2_newname"
done <<< $colonna2

sed replace entire string after match [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hi I'm trying to sed replace the entire string after a match.
my scenario will be inside my file I have the below values:
"XX|TESTFILE|MATCH" "CHANGEME"
"XX|TESTFILE|MATCH1" "CHANGEME1"
I need to replace the string after the text MATCH" " so my expected output will be
"XX|TESTFILE|MATCH" "THIS IS CHANGED"
"XX|TESTFILE|MATCH1" "CHANGEME1"
Hope it is clear and someone will help.
Thank you!
sed -ri '/MATCH\"/ {s/(^\"XX.* \")(.*)(\"$)/\1THIS IS THE CHANGE\3/}'
Using sed with -r flag for regular expressions, search for entries with MATCH followed by a double quote and then when encountered, split the line into three section. Print the first section followed by "THIS IS THE CHANGE" and then the third section.

Need to fetch the password using Regular expression [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
a= <<EOF
Password
:
7UV1ceFQ (You will be asked to change this after logging in for the first time)
EOF
I need to extract the value "7UV1ceFQ" using regular expression, I have tried using '/Password : 7UV1ceFQ/ but it's not working, I think it's because next line character is included, Can anyone please suggest me to exact this value?
▶ a[/^\S+(?=\s\(You will be)/]
#⇒ "7UV1ceFQ"
The regular expression above reads as:
starting with a new line start ^
get all non-space symbols greedy \S+
until the positive lookahead (?=\s\(You will be)

Using read command [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am extremely confused about using the read command. Can someone please explain this to me? For example if I have:
An executable file called script, containing
read first second
echo $first
echo $second
and you call it with:
echo This is a line of input | ./script
What happens and why? I can't get it to work and something is supposed to displayed
Running help read gives this info:
The line is split into fields as with word splitting, and the first
word is assigned to the first NAME, the second word to the second
NAME, and so on, with any leftover words assigned to the last NAME.
So what's happening here is that the first word is assigned to the variable $first, and the rest of the input line assigned to the last variable $second.
If you want to keep the first word in $first and the second word in $second, try adding a $third variable.

Resources