This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes echo with grep Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "echo with grep" Watch "echo with grep" New topic
Author

echo with grep

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I have something like below, the result of the grep is assigned to abcd variable

abcd=`grep -n "^AB.*123456.*" /tmp/file | cut -d: -f1`

when I try to echo this result to a file using echo $abcd>> /tmp/abc it is not working
It works when I run from the command prompt and this gets assigned to abcd but when I try to print the value using echo $abcd i dont get any results..
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2929
    
  12

It seems to work for me. What shell are you using? Bash, Bourne shell, Korn shell? Does the file /tmp/abc exist already before you run the echo command? Is NOCLOBBER set?

Can you echo anything into the file? For example: echo text >> /tmp/abc Does that work?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: echo with grep
 
jQuery in Action, 3rd edition