Apr 25, 2006 #1 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location IN Hi, I want to print the 2nd part of the sentence in the first coulmn. For E.g I want to filter the output project:ranjan which is in the first column in the file.I want to print only ranjan.How can i get this. --Ranjan.
Hi, I want to print the 2nd part of the sentence in the first coulmn. For E.g I want to filter the output project:ranjan which is in the first column in the file.I want to print only ranjan.How can i get this. --Ranjan.
Apr 25, 2006 #2 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi If the first column does not contain spaces and you have [tt]gawk[/tt] or [tt]nawk[/tt] : Code: awk -F '[: ]' '{print $2}' /path/to/input Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi If the first column does not contain spaces and you have [tt]gawk[/tt] or [tt]nawk[/tt] : Code: awk -F '[: ]' '{print $2}' /path/to/input Feherke. http://rootshell.be/~feherke/
Apr 25, 2006 #3 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi Or : Code: awk '{gsub(/.*:/,"",$1);print $1}' /path/to/input Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi Or : Code: awk '{gsub(/.*:/,"",$1);print $1}' /path/to/input Feherke. http://rootshell.be/~feherke/
Apr 25, 2006 Thread starter #4 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location IN Thanks a lot. Its working with gsub. --Ranjan. Upvote 0 Downvote
May 4, 2006 Thread starter #5 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location IN There is one issue: There is a space between project: and ranjan project: ranjan How can i remove the space with awk '{gsub(/.*:/,"",$1);print $1}' /path/to/input Regards, Ranjan. Upvote 0 Downvote
There is one issue: There is a space between project: and ranjan project: ranjan How can i remove the space with awk '{gsub(/.*:/,"",$1);print $1}' /path/to/input Regards, Ranjan.
May 4, 2006 #6 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi The [tt]awk[/tt] will split the line on spaces, so the word "ranjan" will be placed in $2 : Code: awk '{print $2}' /path/to/input If that space is not allways there, the problem become abit complicated. If there is nothing after the word "ranjan", then : Code: awk '{gsub(/.*: ?/,"");print}' /path/to/input Otherwise, post a full input line. Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi The [tt]awk[/tt] will split the line on spaces, so the word "ranjan" will be placed in $2 : Code: awk '{print $2}' /path/to/input If that space is not allways there, the problem become abit complicated. If there is nothing after the word "ranjan", then : Code: awk '{gsub(/.*: ?/,"");print}' /path/to/input Otherwise, post a full input line. Feherke. http://rootshell.be/~feherke/