how to remove two alternate char from file
How to remove alternate char from file using shell script?
if the file content is "1234567890" the output file should be "24680" somebody already told me that following is the solution and it is working. sed 's/\(.\)\(.\)/\2/g' filename now there may be small modification to generate two alternate byte, what it should be? if the file content is "1234567890" the output file should be "125689" |
Just replace the . by .. in the two grouping expressions.
Read man sed or info sed for an explanation of the stream editor. Anyhow, the dot matches any single character, the parenthesis define groups of expressions, and the \2 refers to the second group, so s/\(.\)\(.\)/\2/g means substitute for every group of two characters the second character of the set. Thus sed 's/\(..\)\(..\)/\2/g' filename would substitute, for every group of four characters, the last two characters in the group. By the way, most distributions are shipped with tools to convert from unicode to to alternative encodings. |
Quote:
|
Sure. Look at the (<expression>){n,m} construction in the manual or info documentation (referenced above) for details. (Or look at info grep in the "Regular Expressions" section.) If you don't have it installed, the pinfo command is a nice-to-have "enhanced" info reader. It replaces both the info and man commands and is (IMHO) somewhat easier to navigate.
|
No need regex. KISS
Code:
# echo "1234567890" | awk -vFS= '{for(i=2;i<=NF;i+=2) printf $i}' |
All times are GMT -5. The time now is 03:19 PM. |