06-24-2009
reverse a string based on else
I have a file like this:
Dog Cat One ABCDEFGHIJ house
Dog Cat Two ABCDEFGHIJ house
Cat Cat One ABCDEFGHIJ house
Cat Cat Two ABCDEFGHIJ house
I want to look at $3 and if it says "Two" print out the line except reverse $4.
Dog Cat One ABCDEFGHIJ house
Dog Cat Two JIHGFEDCBA house
Cat Cat One ABCDEFGHIJ house
Cat Cat Two JIHGFEDCBA house
I was trying to just use a substring 'for loop'
awk '{
if ($3 == "One") print $1, $2, $3, $4, $5;
else if ($3 == "Two") print $1, $2, $3, for(i=length($4);i>=1;i--)
print substr($4,i,1), $5
}' infile > outfile &
This isn't working and obviously I'm lost.
Any help would be fantastic.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Can we print any string in reverse order?
For example:
oracle 16294 1 0 Aug 11 ? 0:00 ora_reco_crepd
oracle 16276 1 0 Aug 11 ? 0:19 ora_dbw0_crepd
I need second last column from this output. (0:00 & 0:19).
I can use awk print $2 after reversing the string.
... (4 Replies)
Discussion started by: malaymaru
4 Replies
2. Shell Programming and Scripting
How to get the reverse parsing work.
I have a strings like
aqw-wef-324-err.log
wefd-324r-err.log
efrt-4rfr.log
.
.
i want to have string upto last hypen.
aqw-wef-324
wefd-324r
... (1 Reply)
Discussion started by: senthilk615
1 Replies
3. Filesystems, Disks and Memory
pls help me in getting that program (1 Reply)
Discussion started by: saikiran
1 Replies
4. Shell Programming and Scripting
Hi,
I am very new to perl.
My question:
How i can reverse the given string using substr function but without using reverse function in perl?
Anybody please help.
thanks,
-Lalit (3 Replies)
Discussion started by: email-lalit
3 Replies
5. Programming
Hi all,
I jus wanna print string b after reversing it. but the out put is blank. My code snippet is below. :wall:
int main()
{
char * a, * b;
b = new char;
a = new char;
int len, le;
le = 0;
cout<< " enter your string \n";
cin>> a;
len = strlen(a);
for(int i =... (8 Replies)
Discussion started by: vineetjoshi
8 Replies
6. Shell Programming and Scripting
Guys,
I am trying to find a way to achieve this. I need to print /usr/local/apche/htdocs only from the string /usr/local/apache/htdocs/file.php using the regex. The below did not work. I know a solution with normal cut, I need a way to do this with the awk regex.
awk '/+file.php/' (6 Replies)
Discussion started by: anilcliff
6 Replies
7. Shell Programming and Scripting
Hi All,
I have a String str="Manish". I would like to reverse it.
I know the option to do this in bash is: echo "Manish" | rev
but I have seen an alternate solution somewhere, which states that:
str="Manish" echo $str | awk '{ for(i=length($0);i>=1;i--) printf("%s",substr($0,i,1));... (7 Replies)
Discussion started by: manishdivs
7 Replies
8. Shell Programming and Scripting
here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb
cat dump.sql
INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies
9. Shell Programming and Scripting
Hi All,
I would like to know , how to reverse a given string
example :
Hi how are you
Required Output:
you are how HiThanks (7 Replies)
Discussion started by: santhoshks
7 Replies
10. Shell Programming and Scripting
Hello,
Can anyone explain for me in this script to reverse the string?
1) the "x=x" part, how it works?
$ echo welcome | awk '{ for(i=length;i!=0;i--)x=x substr($0,i,1);}END{print x}'
$ emoclew2) x seems to be an array at the END, but can it automatically print the whole array in awk?
Thanks... (8 Replies)
Discussion started by: yifangt
8 Replies
LEARN ABOUT DEBIAN
vodovod
vodovod(6) Games vodovod(6)
NAME
vodovod - lead the water from the house to the storage tank
SYNOPSIS
vodovod
DESCRIPTION
Vodovod is a free game, released under GNU GPL license. Graphics and programming are done by Milan Babuskov. This is an over-weekend
project for now, so don't expect miracles. However, game is completely playable.
The goal of the game is to reach the highest possible score. You get a limited number of pipes on each level and need to combine them to
lead the water from the house at the top of the screen to the storage tank at the bottom. For each pipe water goes through, you get 20
points and if you fill the cross-pipe both ways, you get 60 points. At end of each level, you are awarded depending on the skill level:
* Beginner: 100 points
* Toolman: 100 points + number of pipes remaining
* Master plumber: 100 points + 2 x number of pipes remaining
Some of the levels have obstacles where you cannot place pipes, checkpoints through which the water must go and holes in the ground that
slow the flow. Select HELP from the main menu to get more info. The game is playable with joystick/joypad: just move it and press buttons
when you go to Options -> Configure controls
USAGE
The goal of the game is to use pipes to connect the house at the top of the screen with the tank at the bottom. You have time to construct
the initial pipeline before the man enters the house.
For each level you get a limited number of pipes, so use them wisely. If you make a mistake, you can place another pipe over it.
There are certain special blocks in the map:
* Blocked Area - You cannot place pipes on these fields.
* Checkpoint - Your pipeline must go through this field.
* Hole in the ground - Slows down the flow.
SEE ALSO
You can find more information at http://home.gna.org/vodovod/
May 2007 vodovod(6)