- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: help for script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 06:58 PM
тАО10-11-2005 06:58 PM
help for script
id Output Description
abc abc123 xxxx
xyz dbname xxx
123 dbname1 xxx
for given above i want to write scritp to take output correspondign id
without space
if abc identified the abc123 output goes to some variablt, i tried but
its output is coming with spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 07:35 PM
тАО10-11-2005 07:35 PM
Re: help for script
awk '$1=="123"{print $2}' your_file_name
will print "dbname1" without any spaces.
if you would like to assign this to a shell variable than something like
myvar=`awk '$1=="123"{print $2}' your_file_name`
will do the job.
hth
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 07:52 PM
тАО10-11-2005 07:52 PM
Re: help for script
export FILE=/abc/ho/
grep $rid ${FILE}/recv.txt | cut -d "=" -f2
if i use this above one output is coming but with spacec For eg:
output
" dbname"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 08:06 PM
тАО10-11-2005 08:06 PM
Re: help for script
It worked for me in this way, no spaces in the output:
(root@server1)[/] export rid=abc
(root@server1)[/] cat xyz
abc abc123 xxxx
xyz dbname xxx
123 dbname1 xxx
(root@server1)[/] export FILE=/
(root@server1)[/] grep $rid ${FILE}xyz | cut -d " " -f2
abc123
(root@server1)[/]
Hope that helps.
Regards,
- Tags:
- cut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 08:15 PM
тАО10-11-2005 08:15 PM
Re: help for script
export $rid=abc
export FILE=/abc/ho/
grep $rid ${FILE}/recv.txt | cut -d " " -f2
should work.
You can also use the awk command instead of the grep and cut commands (only one command invocation)
awk -v rid=$rid '$1==rid{print $2}' ${FILE}/recv.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 08:25 PM
тАО10-11-2005 08:25 PM
Re: help for script
my o/p should be
myvar is output of cut command
/dir/$myvar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 08:30 PM
тАО10-11-2005 08:30 PM
Re: help for script
export $rid=abc
export FILE=/abc/ho/
this:
grep $rid ${FILE}/recv.txt | cut -d " " -f2
or this:
awk -v rid=$rid '$1==rid{print $2}' ${FILE}/recv.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 08:42 PM
тАО10-11-2005 08:42 PM
Re: help for script
Be aware that if in your file you have any string containing "abc", grep will return every line containing "abc", independently of the place where is this chaine in the line.
awk is a good tool to do that, but i find it heavy to use. So i do prefer this kind of approach :
ID="The string to search"
FILE="File to scan"
OUTPUT=
egrep "^$ID +" $FILE | read nop OUTPUT nop
if [ -z "$OUTPUT" ]
then echo "ID $ID not found"
else echo "ID $ID found with OUTPUT $OUTPUT"
fi
When U use egrep (enhanced grep) "^" means beginning of line and " +" means one or more spaces. In this manner U are sure to find $ID in the first field, not $ID somewhere on the line.
Hope this will help
Eric
(PBFWME;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 11:16 PM
тАО10-11-2005 11:16 PM
Re: help for script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 12:30 AM
тАО10-12-2005 12:30 AM